Raymond Hettinger <[email protected]> added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue33380>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com