Automatically convert pre-0.95 annotations to use Annotated
#9570
DJRHails
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Annotatedis objectively a better solution all round, but I've always struggled to adopt it because of the pain to rewrite existing codebases.Recently I've been experimenting with bulk refactoring using libCST, and I've implemented a converter.
Should be easy to use, just
pip install pymender+pymender FastAPIAnnotated ..@router.get('/example')def example_function(
value: int,
query: str = Query("foo"),
zar: str = Query(default="bar", alias="z"),
foo: str = Depends(get_foo),
*,
bar: str = Depends(get_bar),
body: str = Body(...),
) -> str:
return 'example'
@router.get('/example')def example_function(
value: int,
foo: Annotated[str, Depends(get_foo)],
query: Annotated[str, Query()] = "foo",
zar: Annotated[str, Query(alias="z")] = "bar",
*,
bar: Annotated[str, Depends(get_bar)],
body: Annotated[str, Body()],
) -> str:
return 'example'
Beta Was this translation helpful? Give feedback.
All reactions