🐛 Fix evaluating stringified annotations in Python 3.8 & 3.9 (also from __future__ import annotations
)
#1264
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.
I've fixed evaluating stringified annotations in Python 3.9 and less when using the
Annotated[<type>, typer.{Argument,Option}(...)]
syntax. When removing the@needs_py310
decorator from thetest_annotated_argument_in_string_type_with_default
test, it fails with the following error:This problem typically occurs when
from __future__ import annotations
is used with Python prior to 3.10.This PR fixes the problem for Python 3.8 & 3.9 by evaluating string annotations with
typing_extensions.get_annotations(...)
(added in v4.13.0) instead ofinspect.signature(..., eval_str=True)
, which is only available for Python 3.10+. I can't get this to work for Python 3.7, which is still declared as supported despite having reached EOL more than 2 years ago, as typing-extensions v4.13.0 requires Python 3.8+. Nevertheless, this PR fixes the above problem for all non-EOL Python versions and even Python 3.8.