Skip to content

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

Merged
serhiy-storchaka merged 8 commits into
python:mainfrom
skirpichev:text_signature-scope-82062
May 2, 2024
Merged

gh-82062: correctly set module for built-in instance methods in inspect.signature()#115270
serhiy-storchaka merged 8 commits into
python:mainfrom
skirpichev:text_signature-scope-82062

Conversation

@skirpichev

@skirpichevskirpichev commented Feb 11, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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
Comment threadLib/inspect.py Outdated
Comment threadLib/test/test_capi/test_misc.py Outdated
Comment threadMisc/NEWS.d/next/Library/2024-02-11-07-31-43.gh-issue-82062.eeS6w7.rst Outdated
@skirpichev

Copy link
Copy Markdown
MemberAuthor

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

Comment threadMisc/NEWS.d/next/Library/2024-02-11-07-31-43.gh-issue-82062.eeS6w7.rst Outdated
Comment threadMisc/NEWS.d/next/Library/2024-02-11-07-31-43.gh-issue-82062.eeS6w7.rst Outdated
Comment threadMisc/NEWS.d/next/Library/2024-02-11-07-31-43.gh-issue-82062.eeS6w7.rst Outdated
…S6w7.rst
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

@serhiy-storchakaserhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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:mainMay 2, 2024
@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 freeto 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.

4 participants

@skirpichev@JelleZijlstra@serhiy-storchaka@AlexWaygood