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.0.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for typing_as_t-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 513c239fec8cb38f1c5236369c57ceee1b968c6e84aa13c3bd292d1635d81733 |
|
MD5 | 39996ffaf1d45c322536aee207f8d42f |
|
BLAKE2b-256 | 7ede109e85ae55dbd2f1c644dce610d1ec77e13b3844af6d04e0be44b782444e |