8000 gh-132493: Remove __annotations__ usage in inspect._signature_is_functionlike by JelleZijlstra · Pull Request #133415 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132493: Remove __annotations__ usage in inspect._signature_is_functionlike #133415

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 5 commits into from
May 10, 2025

Conversation

JelleZijlstra
Copy link
Member
@JelleZijlstra JelleZijlstra commented May 5, 2025

This check is potentially problematic because it could force evaluation of
annotations unnecessarily. This doesn't trigger for builtin objects (functions,
classes, or modules) with annotations, but it could trigger for third-party objects.

The check was not particularly useful anyway, because it succeeds if __annotations__
is a dict or None, so the only thing this did was guard against objects that have an
__annotations__ attribute that is of some other type. That doesn't seem particularly
useful, so I just removed the check.

…s_functionlike

This check is potentially problematic because it could force evaluation of
annotations unnecessarily. This doesn't trigger for builtin objects (functions,
classes, or modules) with annotations, but it could trigger for third-party objects.

The check was not particularly useful anyway, because it succeeds if ``__annotations__``
is a dict or None, so the only thing this did was guard against objects that have an
``__annotations__`` attribute that is of some other type. That doesn't seem particularly
useful, so I just removed the check.
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.

A nitpick about tests.

@JelleZijlstra
Copy link
Member Author

Thanks! I am planning to backport this since it's better to get the annotation changes all at once in 3.14, and removing unnecessary evaluation of annotations feels like a bugfix.

@JelleZijlstra JelleZijlstra added the needs backport to 3.14 bugs and security fixes label May 9, 2025
@JelleZijlstra JelleZijlstra merged commit cb6596c into python:main May 10, 2025
39 checks passed
@miss-islington-app
Copy link

Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@JelleZijlstra JelleZijlstra deleted the inspect-no-anno branch May 10, 2025 01:42
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 10, 2025
…s_functionlike (pythonGH-133415)

This check is potentially problematic because it could force evaluation of
annotations unnecessarily. This doesn't trigger for builtin objects (functions,
classes, or modules) with annotations, but it could trigger for third-party objects.

The check was not particularly useful anyway, because it succeeds if ``__annotations__``
is a dict or None, so the only thing this did was guard against objects that have an
``__annotations__`` attribute that is of some other type. That doesn't seem particularly
useful, so I just removed the check.
(cherry picked from commit cb6596c)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@bedevere-app
Copy link
bedevere-app bot commented May 10, 2025

GH-133796 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 10, 2025
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.

2 participants
0