Skip to content

Conversation

skirpichev
Copy link
Contributor

@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
Contributor 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
@skirpichev
Copy link
Contributor Author

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

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
@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.

4 participants