typing-as-t


Nametyping-as-t JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/jaykv/import-typing-as-t
SummaryLibCST codemod to transform typing imports
upload_time2024-05-06 02:47:48
maintainerNone
docs_urlNone
authorJay
requires_python<4.0,>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # import-typing-as-t
LibCST Codemod to transform relative typing import (`from typing import...`) or generic typing import (`import typing`) and their refs to `import typing as t` + `t.` prefixed refs respectively.

# Install
* `pip install typing-as-t`
* Help: `typing-as-t --help`

## Examples

Before:
```python
    from typing import Callable, Optional, Generator, cast, Any

    a : Callable[..., Any] = lambda : "test"
    def func(c: Optional[int] = None) -> Generator:
        return cast(Generator, "blabla")
```

After:
```python
    import typing as t

    a : t.Callable[..., t.Any] = lambda : "test"
    def func(c: t.Optional[int] = None) -> t.Generator:
        return t.cast(t.Generator, "blabla")
```

---

Before:
```python
    from typing import cast, List, Dict, Any, Sequence, TypeAlias, Sequence, Generator

    float_list : TypeAlias = list[float]
    def func(z: float_list, c: Sequence[tuple[tuple[str, int], List[Dict[str, Any]]]] = None) -> Generator:
        return cast(Generator, "blabla")
```

After:
```python
    import typing as t

    float_list : t.TypeAlias = list[float]
    def func(z: float_list, c: t.Sequence[tuple[tuple[str, int], t.List[t.Dict[str, t.Any]]]] = None) -> t.Generator:
        return t.cast(t.Generator, "blabla")
```

---

Before:
```python
    import typing

    a : typing.Callable[..., typing.Any] = lambda : "test"
    def func(c: typing.Optional[int] = None) -> typing.Generator:
        return typing.cast(typing.Generator, "blabla")
```

After:
```python
    import typing as t

    a : t.Callable[..., t.Any] = lambda : "test"
    def func(c: t.Optional[int] = None) -> t.Generator:
        return t.cast(t.Generator, "blabla")
```
---

Before:
```python
from typing import Any, TYPE_CHECKING as TC
from typing import TypeAlias as TA

if TC:
    foo: dict[str, Any]

Vector: TA = list[float]
```

After:

```python
import typing as t

if t.TYPE_CHECKING:
    a: dict[str, t.Any]

Vector: t.TypeAlias = list[float]
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jaykv/import-typing-as-t",
    "name": "typing-as-t",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Jay",
    "author_email": "jay.github0@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/9d/5c/4566624390b66290dab23092f106d6cd2864ecd823acd5d0088c419e0c29/typing_as_t-1.0.1.tar.gz",
    "platform": null,
    "description": "# import-typing-as-t\nLibCST Codemod to transform relative typing import (`from typing import...`) or generic typing import (`import typing`) and their refs to `import typing as t` + `t.` prefixed refs respectively.\n\n# Install\n* `pip install typing-as-t`\n* Help: `typing-as-t --help`\n\n## Examples\n\nBefore:\n```python\n    from typing import Callable, Optional, Generator, cast, Any\n\n    a : Callable[..., Any] = lambda : \"test\"\n    def func(c: Optional[int] = None) -> Generator:\n        return cast(Generator, \"blabla\")\n```\n\nAfter:\n```python\n    import typing as t\n\n    a : t.Callable[..., t.Any] = lambda : \"test\"\n    def func(c: t.Optional[int] = None) -> t.Generator:\n        return t.cast(t.Generator, \"blabla\")\n```\n\n---\n\nBefore:\n```python\n    from typing import cast, List, Dict, Any, Sequence, TypeAlias, Sequence, Generator\n\n    float_list : TypeAlias = list[float]\n    def func(z: float_list, c: Sequence[tuple[tuple[str, int], List[Dict[str, Any]]]] = None) -> Generator:\n        return cast(Generator, \"blabla\")\n```\n\nAfter:\n```python\n    import typing as t\n\n    float_list : t.TypeAlias = list[float]\n    def func(z: float_list, c: t.Sequence[tuple[tuple[str, int], t.List[t.Dict[str, t.Any]]]] = None) -> t.Generator:\n        return t.cast(t.Generator, \"blabla\")\n```\n\n---\n\nBefore:\n```python\n    import typing\n\n    a : typing.Callable[..., typing.Any] = lambda : \"test\"\n    def func(c: typing.Optional[int] = None) -> typing.Generator:\n        return typing.cast(typing.Generator, \"blabla\")\n```\n\nAfter:\n```python\n    import typing as t\n\n    a : t.Callable[..., t.Any] = lambda : \"test\"\n    def func(c: t.Optional[int] = None) -> t.Generator:\n        return t.cast(t.Generator, \"blabla\")\n```\n---\n\nBefore:\n```python\nfrom typing import Any, TYPE_CHECKING as TC\nfrom typing import TypeAlias as TA\n\nif TC:\n    foo: dict[str, Any]\n\nVector: TA = list[float]\n```\n\nAfter:\n\n```python\nimport typing as t\n\nif t.TYPE_CHECKING:\n    a: dict[str, t.Any]\n\nVector: t.TypeAlias = list[float]\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "LibCST codemod to transform typing imports",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/jaykv/import-typing-as-t",
        "Repository": "https://github.com/jaykv/import-typing-as-t"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d9a2fc0a8a7c4d6cafad0e7a5e603409aaa184eac0bba600f33584386db30d79",
                "md5": "9d261b2a9d2c2a6b62e8e236f961b90c",
                "sha256": "5c9cdaf30e42bdc409dfb067e94481fc616b4fab57222f43e1e841b9494be484"
            },
            "downloads": -1,
            "filename": "typing_as_t-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9d261b2a9d2c2a6b62e8e236f961b90c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 5067,
            "upload_time": "2024-05-06T02:47:47",
            "upload_time_iso_8601": "2024-05-06T02:47:47.953574Z",
            "url": "https://files.pythonhosted.org/packages/d9/a2/fc0a8a7c4d6cafad0e7a5e603409aaa184eac0bba600f33584386db30d79/typing_as_t-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9d5c4566624390b66290dab23092f106d6cd2864ecd823acd5d0088c419e0c29",
                "md5": "d05edd985d2f9aac3edfb4b87243450b",
                "sha256": "3795ef56b2098f250cb59d2d4a91511889e93ff6f01aac884da06503d9e6e172"
            },
            "downloads": -1,
            "filename": "typing_as_t-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d05edd985d2f9aac3edfb4b87243450b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 3795,
            "upload_time": "2024-05-06T02:47:48",
            "upload_time_iso_8601": "2024-05-06T02:47:48.857127Z",
            "url": "https://files.pythonhosted.org/packages/9d/5c/4566624390b66290dab23092f106d6cd2864ecd823acd5d0088c419e0c29/typing_as_t-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-06 02:47:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jaykv",
    "github_project": "import-typing-as-t",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "typing-as-t"
}
        
Jay
Elapsed time: 0.27764s