This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author a-feld
Recipients a-feld, rhettinger
Date 2018-04-28.22:40:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1524955212.89.0.682650639539.issue33380@psf.upfronthosting.co.za>
In-reply-to
Content
Python 3.7 made several performance improvements to the namedtuple class as part of https://bugs.python.org/issue28638

Prior to the implementation of bpo-28638, the __module__ attribute for a namedtuple's methods (e.g. _asdict) would return the value 'namedtuple_%s' % typename (e.g. namedtuple_Point).

Due to the optimizations made, the __module__ attribute for a namedtuple's methods now returns 'collections'.

The proposed change as part of this issue is to report the more accurate derived module name for the namedtuple methods. Updating the __module__ attribute should help debug and introspection tools more accurately report the details of executing calls (in profilers for example).

Example from Python 3.6:
>>> from collections import namedtuple
>>> Point = namedtuple('Point', ('x', 'y'))
>>> p1 = Point(1,2)
>>> p1._asdict.__module__
'namedtuple_Point'

Example from Python 3.7.0b3:
>>> from collections import namedtuple
>>> Point = namedtuple('Point', ('x', 'y'))
>>> p1 = Point(1,2)
>>> p1._asdict.__module__
'collections'

Desired behavior:
>>> from collections import namedtuple
>>> Point = namedtuple('Point', ('x', 'y'))
>>> p1 = Point(1,2)
>>> p1._asdict.__module__
'__main__'
History
Date User Action Args
2018-04-28 22:40:12a-feldsetrecipients: + a-feld, rhettinger
2018-04-28 22:40:12a-feldsetmessageid: <1524955212.89.0.682650639539.issue33380@psf.upfronthosting.co.za>
2018-04-28 22:40:12a-feldlinkissue33380 messages
2018-04-28 22:40:12a-feldcreate