{"id":13800437,"url":"https://github.com/PrettyWood/future-typing","last_synced_at":"2025-05-13T09:31:38.423Z","repository":{"id":57432718,"uuid":"332897879","full_name":"PrettyWood/future-typing","owner":"PrettyWood","description":"Backport for type hinting generics in standard collections and union types as X | Y","archived":false,"fork":false,"pushed_at":"2021-05-14T12:04:33.000Z","size":46,"stargazers_count":18,"open_issues_count":5,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T20:35:24.131Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/PrettyWood.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}},"created_at":"2021-01-25T22:09:32.000Z","updated_at":"2025-04-16T11:02:11.000Z","dependencies_parsed_at":"2022-09-19T08:11:05.198Z","dependency_job_id":null,"html_url":"https://github.com/PrettyWood/future-typing","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrettyWood%2Ffuture-typing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrettyWood%2Ffuture-typing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrettyWood%2Ffuture-typing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrettyWood%2Ffuture-typing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PrettyWood","download_url":"https://codeload.github.com/PrettyWood/future-typing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253913137,"owners_count":21983264,"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":[],"created_at":"2024-08-04T00:01:12.615Z","updated_at":"2025-05-13T09:31:37.097Z","avatar_url":"https://github.com/PrettyWood.png","language":"Python","funding_links":[],"categories":["Backports and improvements"],"sub_categories":[],"readme":"# future-typing\n[![Tests](https://github.com/PrettyWood/future-typing/workflows/Tests/badge.svg)](https://github.com/PrettyWood/future-typing/actions)\n[![codecov](https://codecov.io/gh/PrettyWood/future-typing/branch/main/graph/badge.svg)](https://codecov.io/gh/PrettyWood/future-typing)\n[![pypi](https://img.shields.io/pypi/v/future-typing.svg)](https://pypi.python.org/pypi/future-typing)\n[![versions](https://img.shields.io/pypi/pyversions/future-typing.svg)](https://github.com/PrettyWood/future-typing)\n[![license](https://img.shields.io/github/license/PrettyWood/future-typing.svg)](https://github.com/PrettyWood/future-typing/blob/master/LICENSE)\n\nUse generic type hints and new union syntax `|` with python 3.6+\n\nIf you just want to use new annotations for type checkers like `mypy`, then do not use this library\nand simply add `from __future__ import annotations`.\nBut if you want to use those annotations at runtime, then you may be at the right place!\n\nThis library exposes:\n\n- `transform_annotation`, which will transform `list[str|int|float]` into\n  * `typing.List[typing.Union[str, int, float]]` for python 3.6 to 3.8\n  * `list[typing.Union[str, int, float]]` for python 3.9 (since generic types are natively supported)\n\n- a custom source code encoding `future_typing` that you can use to trigger the transformation at\n  interpretation time\n\n- a CLI to see the transformed source\n\n## Installation\n\n``` bash\n    pip install future_typing\n```\n\n## Codec\nJust add this custom source code encoding at the top of your file\n```\n# -*- coding: future_typing -*-\n```\n\nand then use `|` and `list[str]`, `dict[str, int]`, ... as if you were using `python 3.10`\n\n```python\n# -*- coding: future_typing -*-\nfrom typing import Literal\n\n\nclass C:\n    @staticmethod\n    def g(t: tuple[int, ...]) -\u003e tuple[int, ...]:\n        return t\n\n\ndef f(a: list[str | int] | dict[str, str], b: Literal['pika'] | None = None) -\u003e type[C]:\n    x: set[str | int] = set(a)\n    y: frozenset[str] = frozenset(['y1', 'y2'])\n    t: tuple[int, ...] = (1, 2)\n    print(f'it works! a: {a!r}, b: {b!r}')\n    return C\n\n\nf(['a', 'b', 1], 'pika')\n```\n\n```console\n$ python3.8 pika.py\nit works! a: ['a', 'b'], b: 'pika'\n\n$ mypy pika.py\nSuccess: no issues found in 1 source file\n```\n\n## CLI\n```console\n$ future_typing pika.py\nimport typing as typing___\nfrom typing import Literal\n\n\nclass C :\n    @staticmethod\n    def g (t :typing___.Tuple [int ,...])-\u003etyping___.Tuple [int ,...]:\n        return t\n\n\ndef f (a :typing___.Union [typing___.List [typing___.Union [str ,int ]],typing___.Dict [str ,str ]],b :typing___.Union [Literal ['pika'],None ]=None )-\u003etyping___.Type [C ]:\n    x :typing___.Set [typing___.Union [str ,int ]]=set (a )\n    y :typing___.FrozenSet [str ]=frozenset (['y1','y2'])\n    t :typing___.Tuple [int ,...]=(1 ,2 )\n    print (f'it works! a: {a!r}, b: {b!r}')\n    return C\n\n\nf (['a','b',1 ],'pika')\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPrettyWood%2Ffuture-typing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPrettyWood%2Ffuture-typing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPrettyWood%2Ffuture-typing/lists"}