Derived from the flake8-boolean-trap linter.
What it does#
Checks for the use of boolean positional arguments in function definitions,
as determined by the presence of a
bool type hint.
Why is this bad?#
Calling a function with boolean positional arguments is confusing as the meaning of the boolean value is not clear to the caller and to future readers of the code.
The use of a boolean will also limit the function to only two possible behaviors, which makes the function difficult to extend in the future.
Instead, consider refactoring into separate implementations for the
False cases, using an
Enum, or making the argument a
keyword-only argument, to force callers to be explicit when providing
In preview, this rule will also flag annotations that include boolean
bool | int.
Instead, refactor into separate implementations:
Or, refactor to use an
Or, make the argument a keyword-only argument: