Repository navigation
gh-161912: Try calling __annotate__ functions with Format.VALUE before using fake globals in call_annotate_function - #162152
Open
DavidCEllis wants to merge 4 commits into
Conversation
Some tests checked VALUE_WITH_FAKE_GLOBALS was always called by defining annotate functions that were different. These now test this only if the VALUE format fails. Adds tests for the expected call order in Format.FORWARDREF failure and for avoiding a double `VALUE` call in get_annotations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes
call_annotate_function(annotate, Format=Format.FORWARDREF)tryannotate(Format.VALUE)before constructing a fake globals dict and usingFormat.VALUE_WITH_FAKE_GLOBALS.This call is used in places like
TypedDictto get the annotations in a metaclass. In cases whereFormat.VALUEwould succeed, trying it first is significantly faster especially in cases like #161912 where the globals dict is large and copying it is expensive.Tools that use
get_annotationsalready effectively have this fast path asget_annotationstries__annotations__first which will useFormat.VALUE. As such this adds a_skip_value_calltocall_annotate_functionto skip retrying that when being used fromget_annotations.There were a few tests that checked using
Format.FORWARDREFwould useFormat.VALUE_WITH_FAKE_GLOBALSalways and not useFormat.VALUE. These tests have been updated to check both thatFormat.VALUEis used and thatFormat.VALUE_WITH_FAKE_GLOBALSis still used ifFormat.VALUEfails.