-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty __module__ attribute for built-in static methods #115231
Comments
…hods" This reverts commit ff758ab.
Hmm, above code snippet works on 3.8+ as well, e.g.: Python 3.9.19+ (heads/3.9:3f5d9d12c7, Aug 29 2024, 13:17:09)
[GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class Spam:
... @staticmethod
... def foo():
... pass
...
>>> Spam.foo.__module__
'__main__'
>>> |
Static and class methods in Python classes copy attributes from the wrapped methods. But unbound built-in methods do not have the >>> collections.deque.append.__module__
Traceback (most recent call last):
File "<python-input-15>", line 1, in <module>
collections.deque.append.__module__
AttributeError: 'method_descriptor' object has no attribute '__module__'. Did you mean: '__reduce__'?
>>> collections.deque().append.__module__ is None
True We should first decide whether we need the |
That should be helpful for introspection. E.g. now the |
Bug report
Bug description:
An example:
c.f. pure-python staticmethod:
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()
hastype
argument and we could query value of its__module__
attribute.Edit: BTW, same happens for class methods, e.g.:
Probably this should be fixed as well.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: