You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is a callable which produces a new namedtuple type.
It can also be used as a base in the class statement for creating a new namedtuple type.
In both cases it is not a real class. You cannot create an instance of NamedTuple or a subclass of NamedTuple. But it is implemented as a class, and help() shows methods and data descriptors for it, which are useless.
The proposed PR implements NamedTuple like a function. Implementation of the __mro_entries__ method allows to use it as a base in the class statement.
This seems to have caused a test failure in astroid project. I am not sure if the fix needs to be done from their end probably relying on some implementation detail or from the patch itself. Feel free to ignore if it's a third-party only error.
Activity
serhiy-storchaka commentedon Apr 4, 2020
typing.NamedTuple is used in two ways.
In both cases it is not a real class. You cannot create an instance of NamedTuple or a subclass of NamedTuple. But it is implemented as a class, and help() shows methods and data descriptors for it, which are useless.
The proposed PR implements NamedTuple like a function. Implementation of the __mro_entries__ method allows to use it as a base in the class statement.
serhiy-storchaka commentedon Apr 4, 2020
See also bpo-40187.
serhiy-storchaka commentedon Apr 8, 2020
New changeset a2ec069 by Serhiy Storchaka in branch 'master':
bpo-40185: Refactor typing.NamedTuple (GH-19371)
a2ec069
tirkarthi commentedon Aug 10, 2020
This seems to have caused a test failure in astroid project. I am not sure if the fix needs to be done from their end probably relying on some implementation detail or from the patch itself. Feel free to ignore if it's a third-party only error.
Reproducer script : /tmp/namedtuple_astroid.py
Before this commit :
python /tmp/namedtuple_astroid.py
Instance of typing.NamedTuple
After this commit :
serhiy-storchaka commentedon Aug 10, 2020
So mod.body[-1].value is a call:
I do not know what Astroid does with this node, but seem the problem is in its infer() method.