-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-138764: annotationlib - Make call_annotate_function fallback to using VALUE annotations if both the requested format and VALUE_WITH_FAKE_GLOBALS are not implemented
#138803
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
Conversation
… VALUE annotations
|
I also prefer this over #138788 because I think |
|
I like this too. We might need to extend the listing under https://docs.python.org/3.14/library/annotationlib.html#annotationlib.get_annotations explaining how the different formats work (and in any case, this needs a NEWS entry). |
|
I had a go at extending the descriptions of the formats. This made me realise I was describing behaviour that there wasn't a test for as a fall back so added some extra tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, left some small tweaks.
Accept suggestions Co-authored-by: Jelle Zijlstra <[email protected]>
Misc/NEWS.d/next/Library/2025-09-12-09-34-37.gh-issue-138764.mokHoY.rst
Outdated
Show resolved
Hide resolved
|
Thanks @DavidCEllis for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…k to using `VALUE` annotations if both the requested format and `VALUE_WITH_FAKE_GLOBALS` are not implemented (pythonGH-138803) (cherry picked from commit 95c257e) Co-authored-by: David Ellis <[email protected]>
|
GH-140426 is a backport of this pull request to the 3.14 branch. |
…ck to using `VALUE` annotations if both the requested format and `VALUE_WITH_FAKE_GLOBALS` are not implemented (GH-138803) (#140426) gh-138764: annotationlib: Make `call_annotate_function` fallback to using `VALUE` annotations if both the requested format and `VALUE_WITH_FAKE_GLOBALS` are not implemented (GH-138803) (cherry picked from commit 95c257e) Co-authored-by: David Ellis <[email protected]>
Alternative to #138788 - instead of raising the
NotImplementedErrorthis falls back to calling an annotate function withFormat.VALUEif both the specified format andFormat.VALUE_WITH_FAKE_GLOBALSare both not implemented.I think this may be more useful behaviour than #138788 ?
If
VALUEalso fails, then the only option was failure from the start. I think it's more consistent to raise the error fromVALUEannotations in that case.Using the examples from the other PR:
On main, and with this patch:
{'x': 'str'}Main:
Patch:
{'x': 'str'}call_annotate_functionshould checkVALUE_WITH_FAKE_GLOBALSis implemented before calling in a namespace with empty fake globals #138764