GitXplorerGitXplorer
a

mypy-strict-kwargs

public
4 stars
0 forks
0 issues

Commits

List of commits on branch main.
Verified
f24820ae97aa50d1966060ddd38786da210ac492

Merge pull request #55 from adamtheturtle/per-file-ignores

aadamtheturtle committed 14 hours ago
Verified
27f397983f9dc59c39ff85bea641cba73d613b14

Use new format for pylint-per-file-ignores

aadamtheturtle committed 15 hours ago
Verified
133f6711fa3796d47c6f0c9b1eb27d5310a1cd32

Merge pull request #54 from adamtheturtle/dependabot/pip/ruff-0.9.2

ggithub-actions[bot] committed 2 days ago
Verified
d60552ca0710af4b7748ea14e929013dcec6cf41

Bump ruff from 0.9.1 to 0.9.2

ddependabot[bot] committed 2 days ago
Verified
3e9ca64c1547a76ec28fcbc8be772783eb858166

Merge pull request #53 from adamtheturtle/bump-uv-precommit

aadamtheturtle committed 2 days ago
Verified
0bc4e4812fea1ebc76b8f1bdbcb2772de13534d6

Bump uv in pre-commit hooks to 0.5.20

aadamtheturtle committed 2 days ago

README

The README file for this repository.

|Build Status| |codecov| |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.

.. code-block:: python

"""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

.. code-block:: shell

pip install mypy-strict-kwargs

This is tested on Python |minimum-python-version|+.

Configure mypy to use the plugin

Add the plugin to your mypy configuration file <https://mypy.readthedocs.io/en/stable/config_file.html>_:

.ini files:

.. code-block:: ini

[mypy] plugins = mypy_strict_kwargs

.toml files:

.. code-block:: toml

[tool.mypy]

plugins = [ "mypy_strict_kwargs", ]

.. |Build Status| image:: https://github.com/adamtheturtle/mypy-strict-kwargs/actions/workflows/ci.yml/badge.svg?branch=main :target: https://github.com/adamtheturtle/mypy-strict-kwargs/actions .. |codecov| image:: https://codecov.io/gh/adamtheturtle/mypy-strict-kwargs/branch/main/graph/badge.svg :target: https://codecov.io/gh/adamtheturtle/mypy-strict-kwargs .. |PyPI| image:: https://badge.fury.io/py/mypy-strict-kwargs.svg :target: https://badge.fury.io/py/mypy-strict-kwargs .. |minimum-python-version| replace:: 3.10