Skip to main content

Enforce using keyword arguments where possible.

Project description

strict-kwargs

Fast enforcement of keyword arguments at call sites, without mypy or ty plugins. Detects positional arguments and rewrites them to keyword arguments automatically.

def add(a: int, b: int) -> int: ...

add(a=1, b=2)  # OK
add(1, 2)      # error: too many positional args  ->  fix rewrites to add(a=1, b=2)

Install

uv tool install strict-kwargs   # or: pip install strict-kwargs

Usage

strict-kwargs .                 # check a directory (exit 0 = clean, 1 = violations, 2 = error)
strict-kwargs fix .             # rewrite positional args to keyword args in place
strict-kwargs fix --diff .      # preview the rewrite, write nothing
strict-kwargs --python .venv .  # point the ty fallback at an environment

fix is conservative: it never rewrites a call it would not report, and leaves *args/**kwargs unpacking, synthesized constructors, unmatched overloads, and ambiguous ty resolutions untouched (reporting how many it declined). ty-resolved calls are rewritten only when ty reports one concrete callable signature with complete parameter names; overloaded callees are rewritten only when the call-site hover selects one indexed overload arm and the rewritten arguments have precise literal or annotation types. --python accepts an interpreter, venv, or sys.prefix (mirrors ty check --python) for third-party packages outside an activated venv or <project>/.venv. A path that does not exist is a hard error (exit 2), like ruff, rather than a silent "clean" result; a nonexistent --python is reported on stderr and the run falls back to ty's own environment discovery.

pre-commit

repos:
  - repo: https://github.com/adamtheturtle/strict-kwargs-pre-commit
    rev: 2026.5.16.post1  # pin to a release tag
    hooks:
      - id: strict-kwargs

Use the mirror (prebuilt wheel, no Rust toolchain). Pointing repo: at this repository works too but builds from source.

Configuration

In pyproject.toml:

[tool.strict_kwargs]
ignore_names = ["main.func", "builtins.str"]  # fully-qualified names to ignore
debug = false                                  # log debug info and AST dumps to stderr

A missing pyproject.toml, or one without a [tool.strict_kwargs] table, is fine and uses the defaults. A pyproject.toml that exists but cannot be parsed, or whose [tool.strict_kwargs] has the wrong shape or value types (e.g. ignore_names not a list), is a hard error (exit 2) rather than a silent fall back to defaults.

Comparison with mypy-strict-kwargs

mypy-strict-kwargs is a mypy plugin that enforces the same rule. Use strict-kwargs if you type-check with ty or prefer a standalone linter without plugins.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

strict_kwargs-2026.5.19-py3-none-win_amd64.whl (2.1 MB view details)

Uploaded Python 3Windows x86-64

strict_kwargs-2026.5.19-py3-none-manylinux_2_39_x86_64.whl (2.3 MB view details)

Uploaded Python 3manylinux: glibc 2.39+ x86-64

strict_kwargs-2026.5.19-py3-none-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file strict_kwargs-2026.5.19-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for strict_kwargs-2026.5.19-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 38895f9734a573d65be30676268ae4f3ef6a9c681865356c3fbb3195acf3ef87
MD5 467127effb1227eec5c3088ca9c0ab6c
BLAKE2b-256 1b23a2e2a007d83882d88b1a498d2bcebd514d245ee6573694fdbf9154a59446

See more details on using hashes here.

Provenance

The following attestation bundles were made for strict_kwargs-2026.5.19-py3-none-win_amd64.whl:

Publisher: release.yml on adamtheturtle/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 strict_kwargs-2026.5.19-py3-none-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for strict_kwargs-2026.5.19-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 fb769fa05432a0b3bed17ca691cae5a2e07292eceef9df3f3b8b2af41a0fabc7
MD5 3d389c65369133455e3bb825110591f3
BLAKE2b-256 a94119cfa8950aab4a1de459f76564dcd1f5cb51ea52a317a1580e1507839129

See more details on using hashes here.

Provenance

The following attestation bundles were made for strict_kwargs-2026.5.19-py3-none-manylinux_2_39_x86_64.whl:

Publisher: release.yml on adamtheturtle/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 strict_kwargs-2026.5.19-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for strict_kwargs-2026.5.19-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1011559537605fd1cfb03d8c0e1d117828fcc55c9a67001ad651c6ec336e41a9
MD5 a08cc0920244051e6972c9a544b0c0ac
BLAKE2b-256 1724fc3febd4579f80aef4ea4d49717bc5378739ad88dde532b3d11e55c1c703

See more details on using hashes here.

Provenance

The following attestation bundles were made for strict_kwargs-2026.5.19-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on adamtheturtle/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