Skip to main content

flake8-force-keyword-arguments

PyPI PyPI - Wheel Python Version PyPI - Implementation Codecov GitHub last commit (branch) GitHub Workflow Status (branch) Dependabot Status Code Style


A flake8 plugin that is looking for function calls and forces to use keyword arguments if there are more than X (default=2) arguments. And it can ignore positional only or variable arguments functions such as setattr() or Logger.info(). The plugin inspects given modules (via --kwargs-inspect-module, --kwargs-inspect-module-extend) to get signature and to determine whether it is positional only or variable arguments function. The inspection runs only once at the start of the flake8 command and remembers ignore list through runtime.

Installation

pip install flake8-force-keyword-arguments

Usage

Run your flake8 checker as usual.

Example:

flake8 your_module.py

Option

  • --kwargs-max-positional-arguments: How many positional arguments are allowed (default: 2)
  • --kwargs-ignore-function-pattern: Ignore pattern list (default: ('^logger.(:?log|debug|info|warning|error|exception|critical)$', 'setattr$', 'delattr$', 'getattr$'))
  • --kwargs-ignore-function-pattern-extend: Extend ignore pattern list.
  • --kwargs-inspect-module: Inspect module level constructor of classes or functions to gather positional only callables and ignore it on lint. Note that methods are not subject to inspection. (default: ('builtins',))
  • --kwargs-inspect-module-extend: Extend --kwargs-inspect-module
  • --kwargs-inspect-qualifier-option {only_name,only_with_qualifier,both}: For detected positional only callables by inspection, option to append the qualifier or not. e.g. In case builtins.setattr(), both will register builtins.setattr and setattr as positional only function. only_name will register setattr and only_with_qualifier will register builtins.setattr. (default: QualifierOption.BOTH)

Example

code: test.py

from functools import partial

def one_argument(one):
    pass

def two_arguments(one, two):
    pass

def pos_only_arguments(one, two, three, /):  # python 3.8 or higher required
    pass

def variable_arguments(*args):
    pass

variadic = lambda *args: None
curried = partial(variadic, 1)

one_argument(1)
one_argument(one=1)
two_arguments(1, 2)
two_arguments(one=1, two=2)
pos_only_arguments(1, 2, 3)
variadic(1, 2, 3)
curried(2, 3)

Command

flake8 test.py --select FKA1 --kwargs-inspect-module-extend test

test.py:20:1: FKA100 two_arguments's call uses 2 positional arguments, use keyword arguments.

flake8 test.py --select FKA1 --kwargs-inspect-module-extend test --kwargs-ignore-function-pattern-extend ^two_arguments$

No error

flake8 test.py --select FKA1

test.py:16:11: FKA100 partial's call uses 2 positional arguments, use keyword arguments.
test.py:20:1: FKA100 two_arguments's call uses 2 positional arguments, use keyword arguments.
test.py:22:1: FKA100 pos_only_arguments's call uses 3 positional arguments, use keyword arguments.
test.py:23:1: FKA100 variadic's call uses 3 positional arguments, use keyword arguments.
test.py:24:1: FKA100 curried's call uses 2 positional arguments, use keyword arguments.

Limitation

Currently it only inspects given modules and can not inspect (static, class or normal) methods. Because inspection carries import, it is not safe to inspect all possible packages. And method case, the plugin can inspect methods signature and also can determine whether it is positional only or not. But it can not use the information on lint time. Because python is a dynamic typed language and flake8 is basically a static analyzer. That is, flake8 can not get type information of logger.debug(). So even if I know that logging.Logger::debug() is a variadic function, I can not assure that logger is a instance of Logger.

Error codes

Error code Description
FKA100 XXX's call uses N positional arguments, use keyword arguments.

Metadata

Release files for flake8-force-keyword-arguments 2.0.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-force-keyword-arguments 2.0.0
File Size Uploaded
flake8_force_keyword_arguments-2.0.0.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-force-keyword-arguments 2.0.0
File Interpreter ABI Platform
flake8_force_keyword_arguments-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / flake8_force_keyword_arguments-2.0.0.tar.gz

Download URL flake8_force_keyword_arguments-2.0.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
24b41b42b5afa39c58cca5790c5efadb0881f77afbd54ddbb1657f85052a0249
BLAKE2b-256 checksum
How to use checksums
1f443af5619547b4dd332f3143b4627ee148c26a131e79dde98b8f970b27cd07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8

Release files / flake8_force_keyword_arguments-2.0.0-py3-none-any.whl

Download URL flake8_force_keyword_arguments-2.0.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b331e9994f5a03c52d7f6c31bcf356b495ff2fdc0c3e039e6e464ace15d11dec
BLAKE2b-256 checksum
How to use checksums
e40611bc05deeaf00a2b322cd1c716eae6c89a123eb6e10a52038ce110fe5aef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

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