Skip to main content

Python typing update

PyPI PyPI - Python Version GitHub image

Tool to update Python typing syntax. It uses token analysis and

to try and update the typing syntax the best it can.

Important
Every project uses a different formatting style, so always check git diff before comitting any changes! Since this tool uses pyupgrade, it's best used for projects that use it already.

Limitations

Due to the way the tool works, it will reorder the imports multiple times. By default the tool tries to detect if a comment was moved and revert all changes to the file. This can be overwritten by using --force.

Currently, it's not possible to update aliases with a different name. In particular, these need to be updated manually:

Old typing name New
Deque collections.deque
DefaultDict collections.defaultdict
AbstractSet collections.abc.Set
ContextManager contextlib.AbstractContextManager
AsyncContextMananger contextlib.AbstractAsyncContextManager

How it works

  1. Run python-reorder-import to add from __future__ import annotations to each file.
  2. Run pyupgrade to use generic aliases (PEP 585) and alternative union syntax (PEP 604) where possible.
  3. Run autoflake to check if any typing import is now unused. If not, revert changes with git restore.
  4. Remove unused imports with autoflake.
  5. Run isort to try to restore the previous formatting.
  6. Optional: Run black. (Requires black to be added as additional_dependency)
    OR: Run ruff. (Requires ruff to be added as additional_dependency)
  7. Check git diff for modified comments. If one is detected, revert changes and print file name. Can be overwritten with --force.

Setup pre-commit

Add this to the .pre-commit-config.yaml file

repos:
  - repo: https://github.com/cdce8p/python-typing-update
    rev: <insert current tag here!>
    hooks:
      - id: python-typing-update
        stages: [manual]

Run with

pre-commit run --hook-stage manual python-typing-update --all-files

Configuration

--verbose
Always print verbose logging.

--limit
Max number of files that should be changed. No performance improvements, since the limit is only applied after all files have been processed.

--concurrent-files
Number of files to process concurrently during initial load.

--full-reorder
Use additional options from python-reorder-imports to rewrite

  • Imports from mypy_extensions and typing_extensions when possible.

--keep-updates
Keep updates even if no import was removed. Use with caution, might result in more errors.

--black
Run black formatting after updates.
To use it, add black as additional_dependency in your .pre-commit-config.yaml.

        additional_dependencies:
          - black==<insert current version here!>

--ruff
Run ruff check --fix and ruff format after updates.
To use it, add ruff as additional_dependency in your .pre-commit-config.yaml.

        additional_dependencies:
          - ruff==<insert current version here!>

--disable-committed-check
Don't abort with uncommitted changes. Don't use it in production! Risk of losing uncommitted changes.

Different mode options

--check
Check if files would be modified. Return with exitcode 1 or 0 if not. Useful for CI runs.

--force
Don't revert changes if a modified comment is detected. Check git diff before committing!

--only-force
Only update files which are likely to require extra work. Check git diff before committing!

Python version options

--py311-plus
Set the minimum Python syntax version to 3.11. (Default: 3.11)

--py312-plus
Set the minimum Python syntax version to 3.12. (Default: 3.11)

--py313-plus
Set the minimum Python syntax version to 3.13. (Default: 3.11)

--py314-plus
Set the minimum Python syntax version to 3.14. (Default: 3.11)

--py315-plus
Set the minimum Python syntax version to 3.15. (Default: 3.11)

License

This Project is licensed under the MIT license. See LICENSE for the full license text.

Metadata

Release files for python-typing-update 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-typing-update 0.9.0
File Size Uploaded
python_typing_update-0.9.0.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-typing-update 0.9.0
File Interpreter ABI Platform
python_typing_update-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.1 kB

Release files / python_typing_update-0.9.0.tar.gz

Download URL python_typing_update-0.9.0.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a787dc00a36923ae2b3433b489190039ae73d34f0c8d22d4ecb4cf9aac388642
BLAKE2b-256 checksum
How to use checksums
928317c8297f56fd65208a0b5d71928f55feef769e415ef72cdf983c2afb8753
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.

Transparency log

Release files / python_typing_update-0.9.0-py3-none-any.whl

Download URL python_typing_update-0.9.0-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8eb96a794b03ce8a281a7dd923f605eb63748119950874238471386a9ab6643f
BLAKE2b-256 checksum
How to use checksums
36b2986a6d422f160f7e2d80e51b7b3e378c86c367a6b7a2db28ab6892f0513c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.5

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page