Enforce using keyword arguments where possible.
Project description
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
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 mypy_strict_kwargs-2026.5.20.tar.gz.
File metadata
- Download URL: mypy_strict_kwargs-2026.5.20.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdec43b4a509bf3455feab6c71c08b35b0f70c0e0f09826d2ea9841f1c8b8aca
|
|
| MD5 |
396eb9cc95912682965bbdc70b18ea21
|
|
| BLAKE2b-256 |
8ff192d6e83fc47263df9229723cd35b2db98084480dd63745ab514601db627e
|
Provenance
The following attestation bundles were made for mypy_strict_kwargs-2026.5.20.tar.gz:
Publisher:
release.yml on adamtheturtle/mypy-strict-kwargs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mypy_strict_kwargs-2026.5.20.tar.gz -
Subject digest:
fdec43b4a509bf3455feab6c71c08b35b0f70c0e0f09826d2ea9841f1c8b8aca - Sigstore transparency entry: 1577478503
- Sigstore integration time:
-
Permalink:
adamtheturtle/mypy-strict-kwargs@c14886ef32e7bf2994a808ad1373ddefb388779e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adamtheturtle
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c14886ef32e7bf2994a808ad1373ddefb388779e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mypy_strict_kwargs-2026.5.20-py2.py3-none-any.whl.
File metadata
- Download URL: mypy_strict_kwargs-2026.5.20-py2.py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8466ca64176bc634c9c5c74ebc6a9e1da7686237d177f3f34b5843d5c99033f9
|
|
| MD5 |
710e0fa9748ef90bc5463839be329e95
|
|
| BLAKE2b-256 |
4ecaf7aff70b9c97d287533e2dddc2f565f72e3ef012813b4b640712cab39c60
|
Provenance
The following attestation bundles were made for mypy_strict_kwargs-2026.5.20-py2.py3-none-any.whl:
Publisher:
release.yml on adamtheturtle/mypy-strict-kwargs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mypy_strict_kwargs-2026.5.20-py2.py3-none-any.whl -
Subject digest:
8466ca64176bc634c9c5c74ebc6a9e1da7686237d177f3f34b5843d5c99033f9 - Sigstore transparency entry: 1577478654
- Sigstore integration time:
-
Permalink:
adamtheturtle/mypy-strict-kwargs@c14886ef32e7bf2994a808ad1373ddefb388779e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adamtheturtle
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c14886ef32e7bf2994a808ad1373ddefb388779e -
Trigger Event:
workflow_dispatch
-
Statement type: