Skip to main content

Enforce using keyword arguments where possible.

Project description

Build Status PyPI

mypy-strict-kwargs

Enforce using keyword arguments where possible.

For example, if we have a function which takes two regular argument, there are three ways to call it. With this plugin, mypy will only accept the form where keyword arguments are used.

"""Showcase errors when calling a function without naming the arguments."""


def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b


add(a=1, b=2)  # With this plugin, ``mypy`` will only accept this form
add(1, 2)  # type: ignore[misc]
add(1, b=2)  # type: ignore[misc]

Why?

  • In the same spirit as a formatter - think black or ruff format - this lets you stop spending time discussing whether a particular function call should use keyword arguments.

  • Sometimes positional arguments are best at first, and then more and more are added and code becomes unclear, without anyone stopping to refactor to keyword arguments.

  • The type checker gives better errors when keyword arguments are used. For example, with positional arguments, you may see, Argument 5 to "add" has incompatible type "str"; expected "int". This requires that you count the arguments to see which one is wrong. With named arguments, you get Argument "e" to "add" has incompatible type "str"; expected "int".

Installation

pip install mypy-strict-kwargs

This is tested on Python 3.11+.

Configure mypy to use the plugin

Add the plugin to your mypy configuration file:

pyproject.toml:

[tool.mypy]

plugins = [
    "mypy_strict_kwargs",
]

mypy.ini or .mypy.ini:

[mypy]
plugins = mypy_strict_kwargs

setup.cfg:

[mypy]
plugins = mypy_strict_kwargs

Ignoring functions

You can ignore functions by adding configuration to your mypy configuration file.

pyproject.toml:

[tool.mypy_strict_kwargs]
ignore_names = ["main.func", "builtins.str"]

mypy.ini, .mypy.ini, or setup.cfg:

[mypy_strict_kwargs]
ignore_names = main.func, builtins.str

This is useful especially for builtins which can look strange with keyword arguments. For example, str(object=1) is not idiomatic.

To find the name of a function to ignore, set the following configuration:

pyproject.toml:

[tool.mypy_strict_kwargs]
debug = true

mypy.ini, .mypy.ini, or setup.cfg:

[mypy_strict_kwargs]
debug = true

Then run mypy and look for the debug output.

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

mypy_strict_kwargs-2026.5.20.1.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

mypy_strict_kwargs-2026.5.20.1-py2.py3-none-any.whl (8.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file mypy_strict_kwargs-2026.5.20.1.tar.gz.

File metadata

  • Download URL: mypy_strict_kwargs-2026.5.20.1.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mypy_strict_kwargs-2026.5.20.1.tar.gz
Algorithm Hash digest
SHA256 d30eefd1b9474052594a1a414738160ee6459641e3953ec506a3009cceb40435
MD5 cff11e48b6345c0ec740e3ea1fc3ed94
BLAKE2b-256 4e4443b8cbc8dd9ed89359e451f8433a071557bdeb0b51f5f211dc56d1528bf8

See more details on using hashes here.

Provenance

The following attestation bundles were made for mypy_strict_kwargs-2026.5.20.1.tar.gz:

Publisher: release.yml on adamtheturtle/mypy-strict-kwargs

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

File details

Details for the file mypy_strict_kwargs-2026.5.20.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for mypy_strict_kwargs-2026.5.20.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3fe756c3fa1de37e2745c4e74732ebdfa02a2e47a4bc70625a9d2d5a6950cef1
MD5 98795bb3628ddfb1504931033c70cc82
BLAKE2b-256 34646d7982dab4b32bd8fb3a549029fdceb74ef7ababe5793dcd7669a513dc1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mypy_strict_kwargs-2026.5.20.1-py2.py3-none-any.whl:

Publisher: release.yml on adamtheturtle/mypy-strict-kwargs

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