-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support structural subtyping for named tuples #3521
Comments
If you really want this, can you make it an option in PEP 544? Personally I think it would require an extra marker class, since otherwise if fun() contained |
Not that I really want this, but I have seen this "feature request" at least twice, so that we can at least consider this. Concerning the PEP, I would rather add a common section about
Again, maybe we can just have a class keyword? class Point(NamedTuple, structural=True):
x: int
y: int |
I suppose I caused one of those feature requests myself. :-) As we have now clearly demonstrated, this is one of those features that a requester can easily think is simple to implement, but there are actually many traps in any possible solution. I'm not so sure that NamedTuple and TypedDict are really all that similar (except they are both attempts to handle outdated patterns in a statically-typed world). Now that we have a design for dataclasses, even the current limited OO version of NamedTuple seems already a dead end and I sort of wish we hadn't gone there (extra sad because I originally wanted it). In any case I expect NamedTuple and TypedDict to take different development paths (though we may want to curb our enthusiasm for OO TypedDict definitions given what we're going through for NamedTuple). I propose to stop proposing any new additions to NamedTuple (but TypedDict is something we want to develop at least to the point where it's actually useful for Dropbox). |
Maybe then it makes sense to add a section about |
Actually I think TypedDict needs its own PEP if we want it to be more than a mypy-specific extension. |
OK, less work for me :-) Then this issue can be closed I think. I others don't agree, then they can re-open. |
This appeared in python/typing#427
We can consider allowing code like this:
This seems to be type safe and will be relatively easy to implement after protocols land.
The text was updated successfully, but these errors were encountered: