flake8 plugin to improve your type hints
Project description
flake8-kotoha
KoToHa: Kaizen Type Hint
Install
uvx (Recommended)
The easiest way to run flake8 (without manually installation).
$ uvx --with flake8-kotoha flake8 .
Other options
pipx
$ pipx install --preinstall flake8-kotoha flake8
$ flake8 -h
...
Installed plugins: flake8-kotoha: 0.1.0, ...
venv + pip
$ python -m venv .venv --upgrade-deps
$ .venv/bin/python -m pip install flake8-kotoha
$ .venv/bin/flake8 -h
...
Installed plugins: flake8-kotoha: 0.1.0, ...
uv
$ uv tool install flake8 --with flake8-kotoha
$ flake8 -h
...
Installed plugins: flake8-kotoha: 0.1.0, ...
Usage
def plus_one(numbers: list[int]) -> list[int]:
return [n + 1 for n in numbers]
$ flake8 example.py
example.py:1:14: KTH101 Type hint with abstract type `collections.abc.Iterable` or `collections.abc.Sequence`, instead of concrete type `list`
Error codes
Type hints in function parameters
Use abstract types instead of concrete ones
| error code | description |
|---|---|
| KTH101 | Use Iterable or Sequence instead of list |
| KTH102 | Use Iterable or Sequence instead of tuple |
| KTH103 | Use Iterable instead of set |
| KTH104 | Use Iterable instead of dict |
Rationale
https://docs.python.org/ja/3/library/typing.html#typing.List
Note that to annotate arguments, it is preferred to use an abstract collection type such as
SequenceorIterablerather than to uselistortyping.List.
https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#standard-duck-types
Use Iterable for generic iterables (anything usable in "
for"), and Sequence where a sequence (supporting "len" and "__getitem__") is required
https://typing.readthedocs.io/en/latest/reference/best_practices.html#arguments-and-return-types
For arguments, prefer protocols and abstract types (
Mapping,Sequence,Iterable, etc.).
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flake8_kotoha-0.1.1.tar.gz.
File metadata
- Download URL: flake8_kotoha-0.1.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb2060fdc9db4539a96354330280883971b8144fd312f19cd34067f89fd76ead
|
|
| MD5 |
e523646ea1da5740fae7cddac54aabbf
|
|
| BLAKE2b-256 |
60f045defa8972e7104c485ef51e9fe742cacec656b24d604cb4100f7184ceca
|
Provenance
The following attestation bundles were made for flake8_kotoha-0.1.1.tar.gz:
Publisher:
publish.yml on ftnext/kotoha-python-linter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flake8_kotoha-0.1.1.tar.gz -
Subject digest:
bb2060fdc9db4539a96354330280883971b8144fd312f19cd34067f89fd76ead - Sigstore transparency entry: 779036057
- Sigstore integration time:
-
Permalink:
ftnext/kotoha-python-linter@3748420e0f2b966dc11dbf7483b9e5f733cd7587 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ftnext
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3748420e0f2b966dc11dbf7483b9e5f733cd7587 -
Trigger Event:
release
-
Statement type:
File details
Details for the file flake8_kotoha-0.1.1-py3-none-any.whl.
File metadata
- Download URL: flake8_kotoha-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ffef53b0d0f3401e72a517d2ddfee9342b04941f60b85b148d93b5565042e0a
|
|
| MD5 |
5bd6094eacf36dffb6a8e24befcf64f9
|
|
| BLAKE2b-256 |
8bd7f90be03883180500ce8930e0c48a59169cf0cea742d567a2c68ed05e27be
|
Provenance
The following attestation bundles were made for flake8_kotoha-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on ftnext/kotoha-python-linter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flake8_kotoha-0.1.1-py3-none-any.whl -
Subject digest:
7ffef53b0d0f3401e72a517d2ddfee9342b04941f60b85b148d93b5565042e0a - Sigstore transparency entry: 779036062
- Sigstore integration time:
-
Permalink:
ftnext/kotoha-python-linter@3748420e0f2b966dc11dbf7483b9e5f733cd7587 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ftnext
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3748420e0f2b966dc11dbf7483b9e5f733cd7587 -
Trigger Event:
release
-
Statement type: