Mypy Strict Kwargs

2026.1.12 · active · verified Thu Apr 16

mypy-strict-kwargs is a Mypy plugin that enforces the use of keyword arguments for function parameters that have default values, promoting clearer and less error-prone function calls. As of its current version, 2026.1.12, it follows a date-based release cadence with frequent updates, often several times a year.

Common errors

Warnings

Install

Imports

Quickstart

To use mypy-strict-kwargs, first install it, then enable the plugin in your `mypy.ini` configuration file. The plugin will then enforce that arguments with default values are passed as keyword arguments when a positional argument would suffice, ensuring clarity in function calls. Run `mypy main.py` to see the effect.

# mypy.ini
[mypy]
plugins = mypy_strict_kwargs.plugin

# main.py
def calculate(a: int, b: int, operation: str = "add") -> int:
    if operation == "add":
        return a + b
    elif operation == "subtract":
        return a - b
    else:
        raise ValueError("Invalid operation")

# These calls will pass Mypy checks
print(calculate(1, 2, operation="add"))
print(calculate(a=5, b=3))

# This call will trigger a Mypy strict-kwargs error:
# print(calculate(10, 5, "subtract"))
# To fix, pass 'operation' as a keyword argument:
print(calculate(10, 5, operation="subtract"))

view raw JSON →