Perform entire codebase refactors in a way that is reproducible, testable and reviewable. Obeys .gitignore
by default.
pip install pymender==0.2.0
pymender <codemod> <path_to_project>
Converts FastAPI endpoints to use the preferred Annotated[<type>, Depends(<dependency>)]
syntax rather than : <type> = Depends(<dependency>)
.
Why?
- Default value of the function parameter is the actual default value.
- Reuse of the function is now possible.
- Type-safe usage of the functions, previously 'default' values where not type checked.
- Multi-purpose e.g.
Annotated[str, fastapi.Query(), typer.Argument()]
is now possible.
pymender FastAPIAnnotated <folder-to-upgrade>
Before | After |
---|---|
@router.get('/example') |
@router.get('/example') |
# Run a particular codemod
python3 -m pymender <codemod> <path_to_project>
# e.g.
python3 -m pymender FastAPIAnnotated <path_to_project>
# Run the codemod directly
python3 -m libcst.tool codemode fastapi_annotated.FastAPIAnnotated <path_to_project>
# Run tests
pytest -vv
- libCST which does a lot of the hardwork for this.
- autotyping for showing what was possible.