{"id":16913427,"url":"https://github.com/frostming/fix-future-annotations","last_synced_at":"2025-03-22T10:32:20.845Z","repository":{"id":64101514,"uuid":"572797104","full_name":"frostming/fix-future-annotations","owner":"frostming","description":"A CLI and pre-commit hook to fix future annotations","archived":false,"fork":false,"pushed_at":"2023-02-16T01:00:07.000Z","size":39,"stargazers_count":36,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T10:38:05.270Z","etag":null,"topics":["pre-commit","pre-commit-hook","python","typing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frostming.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-01T03:35:51.000Z","updated_at":"2024-12-07T12:03:01.000Z","dependencies_parsed_at":"2024-10-28T13:15:51.362Z","dependency_job_id":"dce920b8-cd3b-496b-aaa8-b33693da18d6","html_url":"https://github.com/frostming/fix-future-annotations","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostming%2Ffix-future-annotations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostming%2Ffix-future-annotations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostming%2Ffix-future-annotations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostming%2Ffix-future-annotations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frostming","download_url":"https://codeload.github.com/frostming/fix-future-annotations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244273726,"owners_count":20426970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pre-commit","pre-commit-hook","python","typing"],"created_at":"2024-10-13T19:13:22.553Z","updated_at":"2025-03-22T10:32:20.465Z","avatar_url":"https://github.com/frostming.png","language":"Python","readme":"# fix-future-annotations\n\nA CLI and pre-commit hook to upgrade the typing annotations syntax to PEP 585 and PEP 604.\n\n\n## Upgrade Details\n\n### [PEP 585] – Type Hinting Generics In Standard Collections\n\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\u003cth\u003eOld\u003c/th\u003e\u003cth\u003eNew\u003c/th\u003e\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```python\ntyping.Dict[str, int]\nList[str]\n```\n\u003c/td\u003e\u003ctd\u003e\n\n```python\ndict[str, int]\nlist[str]\n```\n\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\n\u003c/table\u003e\n\n\n### [PEP 604] – Allow writing union types as `X | Y`\n\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\u003cth\u003eOld\u003c/th\u003e\u003cth\u003eNew\u003c/th\u003e\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```python\ntyping.Union[str, int]\nOptional[str]\n```\n\u003c/td\u003e\u003ctd\u003e\n\n```python\nstr | int\nstr | None\n```\n\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\n\u003c/table\u003e\n\n### [PEP 563] – Postponed Evaluation of Annotations\n\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\u003cth\u003eOld\u003c/th\u003e\u003cth\u003eNew\u003c/th\u003e\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```python\ndef create() -\u003e \"Foo\": pass\n```\n\u003c/td\u003e\u003ctd\u003e\n\n```python\ndef create() -\u003e Foo: pass\n```\n\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\n\u003c/table\u003e\n\n### Import aliases handling\n\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\u003cth\u003eOld\u003c/th\u003e\u003cth\u003eNew\u003c/th\u003e\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```python\nimport typing as t\nfrom typing import Tuple as MyTuple\n\ndef foo() -\u003e MyTuple[str, t.Optional[int]]:\n    pass\n```\n\u003c/td\u003e\u003ctd\u003e\n\n```python\nfrom __future__ import annotations\n\nimport typing as t\n\ndef foo() -\u003e tuple[str, int | None]:\n    pass\n```\n\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\n\u003c/table\u003e\n\n### Full example\n\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\u003cth\u003eOld\u003c/th\u003e\u003cth\u003eNew\u003c/th\u003e\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```python\nfrom typing import Union, Dict, Optional, Tuple\n\n# non-annotation usage will be preserved\nMyType = Union[str, int]\n\n\ndef foo() -\u003e Tuple[Dict[str, int], Optional[str]]:\n    ...\n```\n\u003c/td\u003e\u003ctd\u003e\n\n```python\nfrom __future__ import annotations\n\nfrom typing import Union\n\n# non-annotation usage will be preserved\nMyType = Union[str, int]\n\n\ndef foo() -\u003e tuple[dict[str, int], str | None]:\n    ...\n```\n\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\n\u003c/table\u003e\n\nUnused import names will be removed, and if `from __future__ import annotations` is not found in the script, it will be automatically added if the new syntax is being used.\n\n## Use as a command line tool\n\n```bash\npython3 -m pip install -U fix-future-annotations\n\nfix-future-annotations my_script.py\n```\n\n## Use as pre-commit hook\n\nAdd the following to your `.pre-commit-config.yaml`:\n\n```yaml\nrepos:\n  - repo: https://github.com/frostming/fix-future-annotations\n    rev: 0.5.0  # a released version tag\n    hooks:\n      - id: fix-future-annotations\n```\n\n## Configurations\n\n`fix-future-annotations` can be configured via `pyproject.toml`. Here is an example:\n\n```toml\n[tool.fix_future_annotations]\nexclude_files = [  # regex patterns to exclude files\n    'tests/.*',\n    'docs/.*',\n]\n\nexclude_lines = [  # regex patterns to exclude lines\n    '# ffa: ignore',   # if a line ends with this comment, the whole *block* will be excluded\n    'class .+\\(BaseModel\\):'  # classes that inherit from `BaseModel` will be excluded\n]\n```\n\n## License\n\nThis work is distributed under [MIT](https://github.com/frostming/fix-future-annotations/blob/main/README.md) license.\n\n[PEP 563]: https://peps.python.org/pep-0563/\n[PEP 585]: https://peps.python.org/pep-0585/\n[PEP 604]: https://peps.python.org/pep-0604/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrostming%2Ffix-future-annotations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrostming%2Ffix-future-annotations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrostming%2Ffix-future-annotations/lists"}