-
-
Notifications
You must be signed in to change notification settings - Fork 672
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
🐛 Fix usage of Annotated
with future annotations in Python 3.7+
#814
🐛 Fix usage of Annotated
with future annotations in Python 3.7+
#814
Conversation
Fixes fastapi#802 `RuntimeError: Type not yet supported: typing_extensions.Annotated[...]` The solution is to use the `get_type_hints` method from `typing_extensions` instead of the built-in in the `typing` module, as it includes backports that support properly evaluating the forward reference.
2fe9e80
to
ab857cb
Compare
PR Review
I checked the changes locally on Linux and all tests pass on 3.8..3.12. I reverted the bugfix, run all tests again on 3.8..3.12 and
|
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.
Thanks for the PR - great catch and fix!
I confirmed locally that the behaviour is broken with Python 3.8 and fixed with this PR.
@ivantodorovich: as a "pro tip", next time you create a PR to resolve a bug, you could consider committing the failing test separately as the first commit. This will run the CI, which will be red, clearly showcasing the problem. Then you'd push your fix, the CI would be rerun and would be green, demonstrating that you've fixed things 😉
One final comment for Tiangolo: not sure whether you want this new test in the tests
root or perhaps some place else like test_compat
- I'll leave it like this for now for you to decide.
Good tip! ❤️ |
Annotated
with future annotations in Python 3.8Annotated
with future annotations in Python 3.7+
Awesome, thank you @ivantodorovich! 🚀 And thanks for the review with all the details @svlandeg! 🙇 This will be available in Typer |
Fixes #802
RuntimeError: Type not yet supported: typing_extensions.Annotated[...]
The solution is to use the
get_type_hints
method fromtyping_extensions
instead of the built-in in thetyping
module, as it includes backports that support properly evaluating the forward reference.