Package: python-typing-update
Python typing updateTool to update Python typing syntax.
It uses token analysis andpython-reorder-importspyupgradeisortautoflakeblackgitto try and update the typing syntax the best it can.ImportantEvery project uses a different formatting style,
so always checkgit diffbefore comitting any changes!
Since this tool usespyupgrade, it's best used for
projects that use it already.LimitationsDue 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 nameNewDequecollections.dequeDefaultDictcollections.defaultdictAbstractSetcollections.abc.SetContextManagercontextlib.AbstractContextManagerAsyncContextManangercontextlib.AbstractAsyncContextManagerHow it worksRunpython-reorder-importto addfrom __future__ import annotationsto each file.Runpyupgradeto use generic aliases (PEP 585)
and alternative union syntax (PEP 604) where possible.Runautoflaketo check if any typing import is now
unused. If not, revert changes withgit restore.Remove unused imports withautoflake.Runisortto try to restore the previous formatting.Optional: Runblack. (Requiresblackto be added asadditional_dependency)Checkgit difffor modified comments.
If one is detected, revert changes and print file name.
Can be overwritten with--force.Setup pre-commitAdd this to the.pre-commit-config.yamlfilerepos:-repo:https://github.com/cdce8p/python-typing-updaterev:<insert current tag here!>hooks:-id:python-typing-updatestages:[manual]Run withpre-commitrun--hook-stagemanualpython-typing-update--all-filesConfiguration--verboseAlways print verbose logging.--limitMax number of files that should be changed. No performance improvements,
since the limit is only appliedafterall files have been processed.--concurrent-filesNumber of files to process concurrently during initial load.--full-reorderUse additional options frompython-reorder-importsto rewrite--py38-plus(default): Imports frommypy_extensionsandtyping_extensionswhen possible.--py39-plus: RewritePEP 585typing imports. Additionallytyping.Hashableandtyping.Sizedwill also be replaced by theircollections.abcequivalents.--keep-updatesKeep updates even if no import was removed. Use with caution, might result in more errors.--blackRunblackformatting after updates.To use it, addblackasadditional_dependencyin your.pre-commit-config.yaml.additional_dependencies:-black==<insert current version here!>--disable-committed-checkDon't abort with uncommitted changes.Don't use it in production!Risk of losing uncommitted changes.Different mode options--checkCheck if files would be modified. Return with exitcode1or0if not. Useful for CI runs.--forceDon't revert changes if a modified comment is detected.
Checkgit diffbefore committing!--only-forceOnly update files which are likely to require extra work.
Checkgit diffbefore committing!Python version options--py37-plusSet the minimum Python syntax version to3.7. (Default:3.8)--py38-plusSet the minimum Python syntax version to3.8. This is the default.--py39-plusSet the minimum Python syntax version to3.9. (Default:3.8)--py310-plusSet the minimum Python syntax version to3.10. (Default:3.8)LicenseThis Project is licensed under the MIT license.
SeeLICENSEfor the full license text.