Skip to main content

Flake8 keyword parameter validation

Project description

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

Project details


Download files

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

Source Distribution

flake8-keyword-params-1.2.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

flake8_keyword_params-1.2.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file flake8-keyword-params-1.2.0.tar.gz.

File metadata

  • Download URL: flake8-keyword-params-1.2.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for flake8-keyword-params-1.2.0.tar.gz
Algorithm Hash digest
SHA256 96a1dad03c0b752761d35f0c98d33aba74bb247d89b9a5bc6f91868d9c8ca026
MD5 c4409550b5ea8ba0c9635005d8a0be96
BLAKE2b-256 4891b78c498a6dd263887b0b8c3ea43c652880b01307b583e1bd7cc52f6e37ce

See more details on using hashes here.

File details

Details for the file flake8_keyword_params-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_keyword_params-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44544a2d067a853ca44035701873fa02909a74e21ec72a1b9aded5851a10041e
MD5 bb90ddaade70c0f2dcf64118f16ed349
BLAKE2b-256 01717b8f68921c3999081f19c37f8a1a057d00ec5ef7d0a8272e7af8335ae057

See more details on using hashes here.

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