You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A first attempt to address #450. Handles the basic case, but forward references have some caveats. typing.get_type_hints doesn't actually seem to use the lexical scope of the definition to resolve the hints. Instead, it looks for the module containing the definition. This means that forward references don't work when (for example) an operation is defined inside a function.
IIUC we're going to end up reimplementing a lot of the new Python 3.14 standard library module annotationlib this way. In particular annotationlib includes new and improved versions of inspect.get_annotations() and typing.ForwardRef and a new typing function typing.evaluate_forward_ref, all of which are also backported to 3.12/13 within typing_extensions.
From the annotationlib documentation it seems to be the case that using evaluate_forward_ref on the output of get_annotations will evaluate hints containing ForwardRefs in the correct scopes, and that this is now recommended as the primary method for evaluating and introspecting annotations with forward references.
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
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.
A first attempt to address #450. Handles the basic case, but forward references have some caveats.
typing.get_type_hintsdoesn't actually seem to use the lexical scope of the definition to resolve the hints. Instead, it looks for the module containing the definition. This means that forward references don't work when (for example) an operation is defined inside a function.