🐛 Fix usage of Annotated with future annotations in Python 3.7+#814
🐛 Fix usage of Annotated with future annotations in Python 3.7+#814tiangolo merged 3 commits intofastapi:masterfrom
Annotated with future annotations in Python 3.7+#814Conversation
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 |
svlandeg
left a comment
There was a problem hiding this comment.
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_hintsmethod fromtyping_extensionsinstead of the built-in in thetypingmodule, as it includes backports that support properly evaluating the forward reference.