Skip to main content

flake8-keyword-params

flake8 plugin to require that optional parameters are keyword-only.

This is a highly opinionated plugin asserting that optional parameters should be keyword-only (see PEP-3102). Requiring keywords for optional parameters generally improves readability at point of use, especially for parameters that are seldomly used or would otherwise fall into the bool trap.

Note that when addressing issues found by this plugin, sometimes a better answer than making the parameter keyword-only is to make it non-optional or position-only (see PEP-570).

Accepting that there are common use cases where a keyword-only parameter offers little value, this plugin allows a safelist of function names and parameters that are allowed to be optional. A small predefined set is included by default, but may be extended or replaced via config options. Feel free to file issues to request more default safe entries, especially any in the Python standard library.

Installation

Standard python package installation:

pip install flake8-keyword-params

Options

keyword-params-safelist : Add a function to the safelist, may be specified more than once

keyword-params-exclude-safelist : Remove a function from the safelist, may be specified more than once

keyword-params-include-name : Include plugin name in messages

keyword-params-no-include-name : Do not include plugin name in messages (default setting)

All options may be specified on the command line with a -- prefix, or can be placed in your flake8 config file.

Safelist options may specify a bare function name, so that all parameters are allowed to be optional without keywords, or a function name, followed by a colon, followed by a parameter name. In the latter case, only the specified parameters may be optional without keywords. Both function names and parameter names may be regular expressions.

For example:

flake8 --keyword-params-safelist=get:default --keyword-params-safelist="from_.*:default"

in .flake8 or setup.cfg

[flake8]
keyword-params-safelist = get:default from_.*:default

or in pyproject.toml:

[tool.flake8]
keyword-params-safelist = ['get:default', 'from_.*:default']

Error Codes

Code Message
KWP001 Optional parameter 'param' should be keyword only

Examples

def foo(x=None):  <-- KWP001

def get(key, default=None):  <-- No error, common use case

Metadata

Release files for flake8-keyword-params 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-keyword-params 1.2.0
File Size Uploaded
flake8-keyword-params-1.2.0.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-keyword-params 1.2.0
File Interpreter ABI Platform
flake8_keyword_params-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / flake8-keyword-params-1.2.0.tar.gz

Download URL flake8-keyword-params-1.2.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
96a1dad03c0b752761d35f0c98d33aba74bb247d89b9a5bc6f91868d9c8ca026
BLAKE2b-256 checksum
How to use checksums
4891b78c498a6dd263887b0b8c3ea43c652880b01307b583e1bd7cc52f6e37ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / flake8_keyword_params-1.2.0-py3-none-any.whl

Download URL flake8_keyword_params-1.2.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
44544a2d067a853ca44035701873fa02909a74e21ec72a1b9aded5851a10041e
BLAKE2b-256 checksum
How to use checksums
01717b8f68921c3999081f19c37f8a1a057d00ec5ef7d0a8272e7af8335ae057
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page