[New-bugs-announce] [issue33380] Update module attribute on namedtuple methods for introspection.

Allan Feldman report at bugs.python.org
Sat Apr 28 18:40:12 EDT 2018


New submission from Allan Feldman <allan.d.feldman at gmail.com>:

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__'

----------
components: Library (Lib)
messages: 315869
nosy: a-feld, rhettinger
priority: normal
severity: normal
status: open
title: Update module attribute on namedtuple methods for introspection.
type: enhancement
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33380>
_______________________________________


More information about the New-bugs-announce mailing list