-
Notifications
You must be signed in to change notification settings - Fork 258
NamedTuples defined via Python 3.6 variable annotations should allow methods #352
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
Comments
Initially I implemented this syntax to mimic the old @gvanrossum what do you think? |
I think it's fine.
|
@ilevkivskyi Seems fine, thank you! |
Well, still needs typing to be synchronized with the CPython repo. |
Done. (Normally we don't keep issues open once the fix is committed to master.) |
I have made a small follow-up PR #364 class X(NamedTuple):
x: int
def _fields(self): # This will be an error
... @gvanrossum If you are not against this, then I will merge it tomorrow. |
This is the mypy implementation of python/typing#352. Also fixes #3075.
Following code should work as expected
At the moment it throws
AttributeError
as there is nodouble
method on the constructed namedtuple.The workaround is to define methods on subclass and set
__slots__ = ()
. But unless I'm missing something, there is no reason why methods shouldn't work as expected.The text was updated successfully, but these errors were encountered: