Message315869
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__' |
|
Date |
User |
Action |
Args |
2018-04-28 22:40:12 | a-feld | set | recipients:
+ a-feld, rhettinger |
2018-04-28 22:40:12 | a-feld | set | messageid: <1524955212.89.0.682650639539.issue33380@psf.upfronthosting.co.za> |
2018-04-28 22:40:12 | a-feld | link | issue33380 messages |
2018-04-28 22:40:12 | a-feld | create | |
|