skirpichev · GitHub

Bug report

Bug description:

An example:

>>> bytes.maketrans.__module__ is None
True

c.f. pure-python staticmethod:

>>> class Spam:
...     @staticmethod
...     def foo():
...         pass
...
>>> Spam.foo.__module__
'__main__'

I'm not sure, maybe this should be treated rather as a feature request. Docs says about the attribute value: "The name of the module the function was defined in, or None if unavailable." But clearly, this value is available: the type_add_method() has type argument and we could query value of its __module__ attribute.

Edit: BTW, same happens for class methods, e.g.:

>>> int.from_bytes.__module__ is None
True

Probably this should be fixed as well.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Read the original on github.com ↗