LibCST codemod to transform typing imports
Project description
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:
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:
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:
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:
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:
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:
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:
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:
import typing as t
if t.TYPE_CHECKING:
a: dict[str, t.Any]
Vector: t.TypeAlias = list[float]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
typing_as_t-1.0.1.tar.gz
(3.8 kB
view details)
Built Distribution
File details
Details for the file typing_as_t-1.0.1.tar.gz
.
File metadata
- Download URL: typing_as_t-1.0.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3795ef56b2098f250cb59d2d4a91511889e93ff6f01aac884da06503d9e6e172 |
|
MD5 | d05edd985d2f9aac3edfb4b87243450b |
|
BLAKE2b-256 | 9d5c4566624390b66290dab23092f106d6cd2864ecd823acd5d0088c419e0c29 |
File details
Details for the file typing_as_t-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: typing_as_t-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c9cdaf30e42bdc409dfb067e94481fc616b4fab57222f43e1e841b9494be484 |
|
MD5 | 9d261b2a9d2c2a6b62e8e236f961b90c |
|
BLAKE2b-256 | d9a2fc0a8a7c4d6cafad0e7a5e603409aaa184eac0bba600f33584386db30d79 |