Skip to content

gh-82062: correctly set module for built-in instance methods in inspect.signature() #115270

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

Merged
merged 8 commits into from
May 2, 2024

Conversation

skirpichev
Copy link
Member

@skirpichev skirpichev commented Feb 11, 2024

The __module__ attribute is missing for instance methods in extension modules, so instead we use in this case __objclass__.__module__.

… inspect.signature()

The ``__module__`` attribute is missing for instance methods in extension
modules, so instead we use in this case ``__objclass__.__module__``.
@skirpichev
Copy link
Member Author

Alternatively, we could set the __module__ attribute for instance methods, see #115232. Right now for built-in instance methods its missing (c.f. pure-python classes):

>>> int.to_bytes.__module__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'method_descriptor' object has no attribute '__module__'. Did you mean: '__reduce__'?

@serhiy-storchaka serhiy-storchaka self-requested a review April 30, 2024 09:04

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@skirpichev
Copy link
Member Author

@serhiy-storchaka, I hope I did requested changes.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…S6w7.rst

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@serhiy-storchaka serhiy-storchaka merged commit 9789440 into python:main May 2, 2024
38 checks passed
@skirpichev skirpichev deleted the text_signature-scope-82062 branch May 3, 2024 00:26
SonicField pushed a commit to SonicField/cpython that referenced this pull request May 8, 2024
…sion modules (pythonGH-115270)

Now inspect.signature() supports references to the module globals in
parameter defaults on methods in extension modules.  Previously it was
only supported in functions.  The workaround was to specify the fully
qualified name, including the module name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants