Skip to content
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

__signature__ in the inspect module #106310

Closed
Gouvernathor opened this issue Jul 1, 2023 · 0 comments
Closed

__signature__ in the inspect module #106310

Gouvernathor opened this issue Jul 1, 2023 · 0 comments
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@Gouvernathor
Copy link
Contributor

Gouvernathor commented Jul 1, 2023

Documentation

The __signature__ attribute is treated by inspect.signature (and inspect.Signature.from_callable) as an override which is returned instead of computing the signature through the ordinary process. __text_signature__ serves a similar purpose but containing a string version of the signature.
That's for the implementation.

None of the two are mentioned in the signature or Signature sections of the inspect module's doc page. However, the inspect.unwrap function's doc entry mentions, in an example, that inspect.signature does recognize the __signature__ attribute, without saying what it does with it.
This is the only mention of __signature__ or __text_signature__ in the doc, excluding changelogs, whatsnew, and the Argument clinic section which is overtly implementation-dependent.
However, it is also mentioned in the PEP 362 which introduced Signature, albeit in the Implementation section.

It should be clarified whether what __signature__ does is documented or not. It's a very useful feature to be able to cache or lie about a function's signature, and I think it should be supported.
If not, then inspect.unwrap should stop mentioning it and use another example.

Linked PRs

@Gouvernathor Gouvernathor added the docs Documentation in the Doc dir label Jul 1, 2023
@terryjreedy terryjreedy added the type-bug An unexpected behavior, bug, or error label Oct 11, 2023
ncoghlan pushed a commit that referenced this issue Oct 20, 2023
Document the __signature__ attribute

Co-authored-by: Alex Waygood <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 20, 2023
Document the __signature__ attribute

(cherry picked from commit b07f232)

Co-authored-by: Gouvernathor <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 20, 2023
Document the __signature__ attribute

(cherry picked from commit b07f232)

Co-authored-by: Gouvernathor <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
hugovk pushed a commit that referenced this issue Oct 23, 2023
hugovk pushed a commit that referenced this issue Oct 23, 2023
@hugovk hugovk closed this as completed Oct 23, 2023
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Document the __signature__ attribute

Co-authored-by: Alex Waygood <[email protected]>
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Document the __signature__ attribute

Co-authored-by: Alex Waygood <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants