Message315977
ISTM collections is the correct module reference because that is where the code is actually defined. A debugging tool should look there instead of in the calling code. This is the way other tools work in Python as well:
>>> from collections.abc import Set
>>> class S(Set):
def __init__(self): pass
def __iter__(self): yield 0
def __len__(self): return 0
def __contains__(self, key): return False
>>> S.__or__.__module__
'collections.abc'
>>> from dataclasses import make_dataclass
>>> P = make_dataclass('P', ['x', 'y'])
>>> P.__repr__.__module__
'dataclasses'
Likewise, the various tools that use closures used to report the module where the closure was defined rather than the module of the caller's code (see functools.cmp_to_key or functools.lru_cache). I say "used to" because the pure Python code is now supplanted by C equivalents where the __module__ attribute__ is appropriately set to None:
# Running from PyPy
>>>> from functools import cmp_to_key
>>>> c = cmp_to_key(lambda x, y: 0)
>>>> c.__init__.__module__
'_functools'
The Data Model section of the Language Reference defines __module__ as follows, "__module__: The name of the module the function was defined in, or None if unavailable." In the prior version of namedtuple(), the function was defined in a virtual module (an execed string). Now, that the methods are defined in a real module, the __module__ attribute should name that real module. |
|
Date |
User |
Action |
Args |
2018-05-01 01:53:28 | rhettinger | set | recipients:
+ rhettinger, pmpp, serhiy.storchaka, a-feld |
2018-05-01 01:53:28 | rhettinger | set | messageid: <1525139608.34.0.682650639539.issue33380@psf.upfronthosting.co.za> |
2018-05-01 01:53:28 | rhettinger | link | issue33380 messages |
2018-05-01 01:53:26 | rhettinger | create | |
|