Skip to main content

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 Sequence or Iterable rather than to use list or typing.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8_kotoha-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flake8_kotoha-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

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

Hashes for flake8_kotoha-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bb2060fdc9db4539a96354330280883971b8144fd312f19cd34067f89fd76ead
MD5 e523646ea1da5740fae7cddac54aabbf
BLAKE2b-256 60f045defa8972e7104c485ef51e9fe742cacec656b24d604cb4100f7184ceca

See more details on using hashes here.

Provenance

The following attestation bundles were made for flake8_kotoha-0.1.1.tar.gz:

Publisher: publish.yml on ftnext/kotoha-python-linter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for flake8_kotoha-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7ffef53b0d0f3401e72a517d2ddfee9342b04941f60b85b148d93b5565042e0a
MD5 5bd6094eacf36dffb6a8e24befcf64f9
BLAKE2b-256 8bd7f90be03883180500ce8930e0c48a59169cf0cea742d567a2c68ed05e27be

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page