Metadata-Version: 2.4
Name: mypy-strict-kwargs
Version: 2026.5.20.1
Summary: Enforce using keyword arguments where possible.
Author-email: Adam Dangoor <adamdangoor@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Adam Dangoor
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Documentation, https://mypy-strict-kwargs.readthedocs.io/en/latest/
Project-URL: Source, https://github.com/adamtheturtle/mypy-strict-kwargs
Keywords: mypy
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.11
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: mypy>=2.0.0
Provides-Extra: dev
Requires-Dist: actionlint-py==1.7.12.24; extra == "dev"
Requires-Dist: check-manifest==0.51; extra == "dev"
Requires-Dist: deptry==0.25.1; extra == "dev"
Requires-Dist: doc8==2.0.0; extra == "dev"
Requires-Dist: doccmd==2026.5.19; extra == "dev"
Requires-Dist: interrogate==1.7.0; extra == "dev"
Requires-Dist: mypy[faster-cache]==2.1.0; extra == "dev"
Requires-Dist: prek==0.4.0; extra == "dev"
Requires-Dist: pydocstringformatter==0.7.5; extra == "dev"
Requires-Dist: pylint[spelling]==4.0.5; extra == "dev"
Requires-Dist: pylint-per-file-ignores==3.2.1; extra == "dev"
Requires-Dist: pyproject-fmt==2.21.2; extra == "dev"
Requires-Dist: pyrefly==1.0.0; extra == "dev"
Requires-Dist: pyright==1.1.409; extra == "dev"
Requires-Dist: pyroma==5.0.1; extra == "dev"
Requires-Dist: pytest==9.0.3; extra == "dev"
Requires-Dist: pytest-cov==7.1.0; extra == "dev"
Requires-Dist: pytest-mypy-plugins==4.0.3; extra == "dev"
Requires-Dist: pyyaml==6.0.3; extra == "dev"
Requires-Dist: ruff==0.15.13; extra == "dev"
Requires-Dist: shellcheck-py==0.11.0.1; extra == "dev"
Requires-Dist: shfmt-py==4.0.0; extra == "dev"
Requires-Dist: sphinx-lint==1.0.2; extra == "dev"
Requires-Dist: strict-kwargs==2026.5.19.post3; extra == "dev"
Requires-Dist: ty==0.0.38; extra == "dev"
Requires-Dist: vulture==2.16; extra == "dev"
Requires-Dist: yamlfix==1.19.1; extra == "dev"
Requires-Dist: zizmor==1.25.2; extra == "dev"
Provides-Extra: release
Requires-Dist: check-wheel-contents==0.6.3; extra == "release"
Dynamic: license-file

|Build Status| |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>`_:

``pyproject.toml``:

.. code-block:: toml

   [tool.mypy]

   plugins = [
       "mypy_strict_kwargs",
   ]

``mypy.ini`` or ``.mypy.ini``:

.. code-block:: ini

   [mypy]
   plugins = mypy_strict_kwargs

``setup.cfg``:

.. code-block:: ini

   [mypy]
   plugins = mypy_strict_kwargs

Ignoring functions
------------------

You can ignore functions by adding configuration to your mypy configuration file.

``pyproject.toml``:

.. code-block:: toml

   [tool.mypy_strict_kwargs]
   ignore_names = ["main.func", "builtins.str"]

``mypy.ini``, ``.mypy.ini``, or ``setup.cfg``:

.. code-block:: ini

   [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``:

.. code-block:: toml

   [tool.mypy_strict_kwargs]
   debug = true

``mypy.ini``, ``.mypy.ini``, or ``setup.cfg``:

.. code-block:: ini

   [mypy_strict_kwargs]
   debug = true

Then run ``mypy`` and look for the debug output.

.. |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
.. |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.11
