A flake8 plugin that checks the use of type alternatives from the typing module over actual run time types, especially from the collections module.
Project description
flake8-typing-collections
A flake8 plugin that checks the use of type alternatives from
the typing
module over actual run time types, especially from
the collections
module.
Options
The plugin offers the following flags to select which errors to enable. All errors that are not explicitly enabled, are not reported.
--tyco_generic_alt
: EnablesTYCO101
,TYCO102
,TYCO103
,TYCO106
,TYCO107
,TYCO108
,TYCO109
,TYCO110
,TYCO111
,TYCO112
,TYCO114
,TYCO115
,TYCO116
,TYCO117
,TYCO118
,TYCO119
,TYCO120
,TYCO121
,TYCO122
,TYCO123
,TYCO124
,TYCO125
,TYCO126
,TYCO127
,TYCO128
,TYCO129
,TYCO130
,TYCO131
, andTYCO132
.--tyco_alias_alt
: EnablesTYCO104
,TYCO105
, andTYCO113
.--tyco_general_args
: EnablesTYCO200
,TYCO201
, andTYCO202
.
If none of these flags is given, the default selection is used instead,
which is --tyco_generic_alt
and --tyco_general_args
.
Error Codes
TYCO1xx class
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:
...
TYCO100
Use typing.Iterable
instead of collections.abc.Iterable
for type annotations.
TYCO101
Use typing.Iterator
instead of collections.abc.Iterator
for type annotations.
TYCO102
Use typing.Reversible
instead of collections.abc.Reversible
for type annotations.
TYCO103
Use typing.Container
instead of collections.abc.Container
for type annotations.
TYCO104
Use typing.Hashable
instead of collections.abc.Hashable
for type annotations.
TYCO105
Use typing.Sized
instead of collections.abc.Sized
for type annotations.
TYCO106
Use typing.Collection
instead of collections.abc.Collection
for type annotations.
TYCO107
Use typing.AbstractSet
instead of collections.abc.Set
for type annotations.
TYCO108
Use typing.MutableSet
instead of collections.abc.MutableSet
for type annotations.
TYCO109
Use typing.Mapping
instead of collections.abc.Mapping
for type annotations.
TYCO110
Use typing.MutableMapping
instead of collections.abc.MutableMapping
for type annotations.
TYCO111
Use typing.Sequence
instead of collections.abc.Sequence
for type annotations.
TYCO112
Use typing.MutableSequence
instead of collections.abc.MutableSequence
for type annotations.
TYCO113
Use typing.ByteString
instead of bytes
for type annotations.
TYCO114
Use typing.Deque
instead of collections.Deque
for type annotations.
TYCO115
Use typing.List
instead of list
for type annotations.
TYCO116
Use typing.Set
instead of set
for type annotations.
TYCO117
Use typing.FrozenSet
instead of frozenset
for type annotations.
TYCO118
Use typing.MappingView
instead of collections.abc.MappingView
for type annotations.
TYCO119
Use typing.KeysView
instead of collections.abc.KeysView
for type annotations.
TYCO120
Use typing.ItemsView
instead of collections.abc.ItemsView
for type annotations.
TYCO121
Use typing.ValuesView
instead of collections.abc.ValuesView
for type annotations.
TYCO122
Use typing.Awaitable
instead of collections.abc.Awaitable
for type annotations.
TYCO123
Use typing.Coroutine
instead of collections.abc.Coroutine
for type annotations.
TYCO124
Use typing.AsyncIterable
instead of collections.abc.AsyncIterable
for type annotations.
TYCO125
Use typing.AsyncIterator
instead of collections.abc.AsyncIterator
for type annotations.
TYCO126
Use typing.ContextManager
instead of contextlib.AbstractContextManager
for type annotations.
TYCO127
Use typing.AsyncContextManager
instead of contextlib.AbstractAsyncContextManager
for type annotations.
TYCO128
Use typing.Dict
instead of dict
for type annotations.
TYCO129
Use typing.DefaultDict
instead of collections.defaultdict
for type annotations.
TYCO130
Use typing.OrderedDict
instead of collections.OrderedDict
for type annotations.
TYCO131
Use typing.Counter
instead of collections.Counter
for type annotations.
TYCO132
Use typing.ChainMap
instead of collections.ChainMap
for type annotations.
TYCO2xx class
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:
...
TYCO200
Use typing.Sequence
or typing.MutableSequence
instead of typing.List
in function arguments.
TYCO201
Use typing.AbstractSet
or typing.MutableSet
instead of typing.Set
in function arguments.
TYCO201
Use typing.Mapping
or typing.MutableMapping
instead of typing.Dict
in function arguments.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file flake8-typing-collections-1.0.tar.gz
.
File metadata
- Download URL: flake8-typing-collections-1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2aa0e3a11919a4c7d67441ba7b3dc1d575bd5b2bfd3ecb2da6a6e122af48ff7a |
|
MD5 | ee3645b9288480b5a0c25bd5bd7b0dc9 |
|
BLAKE2b-256 | 3c54cb3624acf979abaac0ef9cb9a2d2f78a6c739b904a97a491dcb0015e346d |
File details
Details for the file flake8_typing_collections-1.0-py3-none-any.whl
.
File metadata
- Download URL: flake8_typing_collections-1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eea50c447821fd9727ce074a71e356d2e80d5d403ea924d34a467907f5702dfd |
|
MD5 | c93412af3b98c72847b2e187908bf81d |
|
BLAKE2b-256 | 8e3e13ba3fa24c6431ba5938526d21ee2eaf801d360a107dcb578a56f2bcbc13 |