A flake8 plugin that checks the use of type alternatives from
the typing module over actual run time types, especially from
the collections module.
The plugin offers the following flags to select which errors to enable. All errors that are not explicitly enabled, are not reported.
--tyc_generic_alt: EnablesTYC101,TYC102,TYC103,TYC106,TYC107,TYC108,TYC109,TYC110,TYC111,TYC112,TYC114,TYC115,TYC116,TYC117,TYC118,TYC119,TYC120,TYC121,TYC122,TYC123,TYC124,TYC125,TYC126,TYC127,TYC128,TYC129,TYC130,TYC131, andTYC132.--tyc_alias_alt: EnablesTYC104,TYC105, andTYC113.--tyc_general_args: EnablesTYC200,TYC201, andTYC202.
If none of these flags is given, the default selection is used instead,
which is --tyc_generic_alt and --tyc_general_args.
The typing module defines several generic versions of built-in
classes, such as typing.List[T] instead of list. Their usage
is preferred.
# Good
def sum_list(x: List[SupportsFloat]) -> float:
...
# Bad
def sum_list(x: list) -> float:
...Use typing.Iterable instead of collections.abc.Iterable for type annotations.
Use typing.Iterator instead of collections.abc.Iterator for type annotations.
Use typing.Reversible instead of collections.abc.Reversible for type annotations.
Use typing.Container instead of collections.abc.Container for type annotations.
Use typing.Hashable instead of collections.abc.Hashable for type annotations.
Use typing.Sized instead of collections.abc.Sized for type annotations.
Use typing.Collection instead of collections.abc.Collection for type annotations.
Use typing.AbstractSet instead of collections.abc.Set for type annotations.
Use typing.MutableSet instead of collections.abc.MutableSet for type annotations.
Use typing.Mapping instead of collections.abc.Mapping for type annotations.
Use typing.MutableMapping instead of collections.abc.MutableMapping for type annotations.
Use typing.Sequence instead of collections.abc.Sequence for type annotations.
Use typing.MutableSequence instead of collections.abc.MutableSequence for type annotations.
Use typing.ByteString instead of bytes for type annotations.
Use typing.Deque instead of collections.Deque for type annotations.
Use typing.List instead of list for type annotations.
Use typing.Set instead of set for type annotations.
Use typing.FrozenSet instead of frozenset for type annotations.
Use typing.MappingView instead of collections.abc.MappingView for type annotations.
Use typing.KeysView instead of collections.abc.KeysView for type annotations.
Use typing.ItemsView instead of collections.abc.ItemsView for type annotations.
Use typing.ValuesView instead of collections.abc.ValuesView for type annotations.
Use typing.Awaitable instead of collections.abc.Awaitable for type annotations.
Use typing.Coroutine instead of collections.abc.Coroutine for type annotations.
Use typing.AsyncIterable instead of collections.abc.AsyncIterable for type annotations.
Use typing.AsyncIterator instead of collections.abc.AsyncIterator for type annotations.
Use typing.ContextManager instead of contextlib.AbstractContextManager for type annotations.
Use typing.AsyncContextManager instead of contextlib.AbstractAsyncContextManager for type annotations.
Use typing.Dict instead of dict for type annotations.
Use typing.DefaultDict instead of collections.defaultdict for type annotations.
Use typing.OrderedDict instead of collections.OrderedDict for type annotations.
Use typing.Counter instead of collections.Counter for type annotations.
Use typing.ChainMap instead of collections.ChainMap for type annotations.
The documentation of the typing module recommends to use
more general types such as typing.Sequence over specialized
types such as typing.List in function parameters.
# Good
def sum_list(x: Sequence[int]) -> int:
...
# Bad
def sum_list(x: List[int]) -> int:
...Use typing.Sequence or typing.MutableSequence
instead of typing.List in function arguments.
Use typing.AbstractSet or typing.MutableSet
instead of typing.Set in function arguments.
Use typing.Mapping or typing.MutableMapping
instead of typing.Dict in function arguments.