Skip to main content

Mend your Python projects with reproducible refactors

Project description

👷‍♀️ PyMender

Perform entire codebase refactors in a way that is reproducible, testable and reviewable. Obeys .gitignore by default.

Usage

pip install pymender==0.1.1

pymender <codemod> <path_to_project>

What codemods are available?

FastAPIAnnotated

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 .
Before After
@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'

Developer Guide

# 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

Thanks to:

  • libCST which does a lot of the hardwork for this.
  • autotyping for showing what was possible.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymender-0.1.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

pymender-0.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file pymender-0.1.1.tar.gz.

File metadata

  • Download URL: pymender-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for pymender-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e59e3281646c2fbcaf4138217dc99300bd8c5368349d0e1c9bc92f380cbfbb22
MD5 d9c84ca0e7e38d5f18aa5cb0e2f132ea
BLAKE2b-256 8d0afb4c758ba5f9db141b74acb255baf59d9e0716fee84d6966ea7eafe12a22

See more details on using hashes here.

File details

Details for the file pymender-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pymender-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for pymender-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f86f75f1865a7cd9eb162e4b092fbfb60dbc8a791fc0b3006f3216953e95e9be
MD5 cf16f21e04a80e6de026f4b94429129a
BLAKE2b-256 b9e60d7afb2f6b74d0e36da7c6d869de6788edbe8fe50ac5b107ddcba2aca37e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page