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.2.2

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 <folder-to-upgrade>
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.2.2.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymender-0.2.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pymender-0.2.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pymender-0.2.2.tar.gz
Algorithm Hash digest
SHA256 d1e136799fa6bedebfca385bc7f1859334382b0e78500a412725f5ba514bc8f8
MD5 9428cd635050726c168e83e04dd348a0
BLAKE2b-256 f922160081027933908d609ca8397b7907c63b4ee122fa2a9a7ed8c49a9536d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymender-0.2.2.tar.gz:

Publisher: publish.yml on DJRHails/PyMender

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: pymender-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pymender-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1dab6507df87e4ec6eed14f192a7445b63c5050058e188f5c5d283597a08becc
MD5 fefbb247b0f2e09e0f64c08907fa4569
BLAKE2b-256 73644d1b9bb18052b3184e52c52a2b96ef72d7fd853ef6a6e8eb7ad25957ebc7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymender-0.2.2-py3-none-any.whl:

Publisher: publish.yml on DJRHails/PyMender

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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