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.
Accepting that there are common use cases where a keyword 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
Built Distribution
Hashes for flake8-keyword-params-1.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa9a9d5ec520a1c476f948dfe0ce1c00c43db77b2ef7b38243d936d097f09f9a |
|
MD5 | d06d6a064abf4edb0eb6b52071f11e32 |
|
BLAKE2b-256 | 6e1732cbb883df09b286e23471faa21cdf7e4759c23a0954ca188e4502fff331 |
Hashes for flake8_keyword_params-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2a47bfdcd96fa222c291f84aa3bbf4280fbdbf7d7d9327ba811d2fd01634cdc |
|
MD5 | 6afdcf0a6a971889014bb6129c455c6d |
|
BLAKE2b-256 | d5dfe80e20016e75291c44e8820f9666375cdd4bb4747f70487af820f123e2e8 |