Enforce using keyword arguments where possible.
Project description
strict-kwargs
Enforce using keyword arguments where possible.
strict-kwargs is a standalone CLI implemented in Rust. It parses Python with
Ruff's Python parser and AST crates, then uses its own resolver plus
ty for type-aware call resolution where static
names alone are not enough.
For example, if we have a function which takes two regular arguments, there are three ways to call it. With this tool, only the form where keyword arguments are used is accepted.
"""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) # OK
add(1, 2) # strict-kwargs reports this
add(1, b=2) # strict-kwargs reports this
Why?
- In the same spirit as a formatter - think
blackorruff 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.
- Type checkers give 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 getArgument "e" to "add" has incompatible type "str"; expected "int".
How it works
strict-kwargs has two resolution layers:
- A built-in resolver parses checked files, first-party modules, vendored typeshed stubs, and discovered site-packages using Ruff's Python parser and AST crates.
- For calls that need richer inference,
strict-kwargsasks ty's language server for hover and definition information.tyis a required dependency of the Python package so results do not depend on whether it happens to be installed separately.
The fixer uses the same detection path, but only rewrites calls when the target parameter names are known unambiguously.
Installation
uv tool install strict-kwargs
or:
pip install strict-kwargs
This is tested on Python 3.11+.
Usage
strict-kwargs . # check a directory
strict-kwargs fix . # rewrite positional args to keyword args in place
strict-kwargs fix --diff . # preview the rewrite, write nothing
strict-kwargs fix --unsafe-fixes . # include rewrites that may change runtime behavior
strict-kwargs --python .venv . # point type resolution at an environment
Exit codes are:
0: clean1: violations found2: operational error
fix only rewrites calls it can name unambiguously. Ambiguous calls are
counted as declined.
--unsafe-fixes includes broader rewrites that may change runtime behavior.
Today that means synthesized dataclass and NamedTuple constructors.
Use --python to point third-party resolution at an interpreter, virtual
environment, or sys.prefix. Missing paths are errors. A missing --python
path is warned about and ignored.
pre-commit
repos:
- repo: https://github.com/adamtheturtle/strict-kwargs-pre-commit
rev: 2026.5.19.post1 # pin to a release tag
hooks:
- id: strict-kwargs
Configuration
Configuration lives in pyproject.toml:
[tool.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:
[tool.strict_kwargs]
debug = true
Then run strict-kwargs and look for the debug output.
Comparison with mypy-strict-kwargs
mypy-strict-kwargs is a
mypy plugin that enforces the same rule during type checking.
Use strict-kwargs if you type-check with ty, if
you prefer a standalone linter without plugins, or if you want automatic
rewrites with strict-kwargs fix.
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 Distributions
Built Distributions
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 strict_kwargs-2026.5.19.post1-py3-none-win_amd64.whl.
File metadata
- Download URL: strict_kwargs-2026.5.19.post1-py3-none-win_amd64.whl
- Upload date:
- Size: 2.1 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f76888366373bfc68a4054b3950db62bbf5f6f0cc41105174075a1c2d5449a2f
|
|
| MD5 |
a7792cdadcd1b228244e0464cb260413
|
|
| BLAKE2b-256 |
6a757c43d1d64d3e9e466be4b363b88feffd6bf8efcee94fb73f857e2c5f198d
|
Provenance
The following attestation bundles were made for strict_kwargs-2026.5.19.post1-py3-none-win_amd64.whl:
Publisher:
release.yml on adamtheturtle/strict-kwargs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strict_kwargs-2026.5.19.post1-py3-none-win_amd64.whl -
Subject digest:
f76888366373bfc68a4054b3950db62bbf5f6f0cc41105174075a1c2d5449a2f - Sigstore transparency entry: 1572974468
- Sigstore integration time:
-
Permalink:
adamtheturtle/strict-kwargs@f9a663cccbcf23536a31c2c230f344da6bc6ec2c -
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@f9a663cccbcf23536a31c2c230f344da6bc6ec2c -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file strict_kwargs-2026.5.19.post1-py3-none-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: strict_kwargs-2026.5.19.post1-py3-none-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: Python 3, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cece04db61680b521d8c440f58d504e36151e2fcdba7128fbe47e9ebee8ab62b
|
|
| MD5 |
9c321e4ecd1fb03d15a8ab37e8c4ffd2
|
|
| BLAKE2b-256 |
e6e1edcaf1bb90ff778adb1e5613b05a7385f6a061bcd3b976718a82bc0f5fd5
|
Provenance
The following attestation bundles were made for strict_kwargs-2026.5.19.post1-py3-none-manylinux_2_39_x86_64.whl:
Publisher:
release.yml on adamtheturtle/strict-kwargs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strict_kwargs-2026.5.19.post1-py3-none-manylinux_2_39_x86_64.whl -
Subject digest:
cece04db61680b521d8c440f58d504e36151e2fcdba7128fbe47e9ebee8ab62b - Sigstore transparency entry: 1572974647
- Sigstore integration time:
-
Permalink:
adamtheturtle/strict-kwargs@f9a663cccbcf23536a31c2c230f344da6bc6ec2c -
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@f9a663cccbcf23536a31c2c230f344da6bc6ec2c -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file strict_kwargs-2026.5.19.post1-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: strict_kwargs-2026.5.19.post1-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.2 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35499102547c410418edd4da533f19c85f5cb1c6744c670975a6b4591e8b2bf8
|
|
| MD5 |
d86e066e73899f080145c92eba18f247
|
|
| BLAKE2b-256 |
7e459d6b7b03e9b5513dae59182bab05543409468aea77841da8c403c61d9ceb
|
Provenance
The following attestation bundles were made for strict_kwargs-2026.5.19.post1-py3-none-macosx_11_0_arm64.whl:
Publisher:
release.yml on adamtheturtle/strict-kwargs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strict_kwargs-2026.5.19.post1-py3-none-macosx_11_0_arm64.whl -
Subject digest:
35499102547c410418edd4da533f19c85f5cb1c6744c670975a6b4591e8b2bf8 - Sigstore transparency entry: 1572974552
- Sigstore integration time:
-
Permalink:
adamtheturtle/strict-kwargs@f9a663cccbcf23536a31c2c230f344da6bc6ec2c -
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@f9a663cccbcf23536a31c2c230f344da6bc6ec2c -
Trigger Event:
workflow_dispatch
-
Statement type: