A flake8 plugin that helps you scream your code.
SCR119
: Use dataclasses for data containers (example)SCR902
: Use keyword-argument instead of magic boolean (example)SCR903
: Use keyword-argument instead of magic number (example)
You might have good reasons to
ignore some flake8 rules.
To do that, use the standard Flake8 configuration. For example, within the setup.cfg
file:
[flake8]
ignore = SCR106, SCR113, SCR119, SCR9
Dataclasses were introduced with PEP 557 in Python 3.7. The main reason not to use dataclasses is to support legacy Python versions.
Dataclasses create a lot of the boilerplate code for you:
__init__
__eq__
__hash__
__str__
__repr__
A lot of projects use them:
# Bad
foo(False)
bar(True)
# Good
foo(verbose=False)
bar(enable_magic=True)
The false-positives that are currentl not possible to fix are in positional-only arguments. There is no way to determine in the AST given by Flake8 if a function has positional-only arguments.
# Bad
foo(42, 1.234)
# Good
foo(the_answer=42, flux_compensation=1.234)
The false-positives that are currentl not possible to fix are in positional-only arguments. There is no way to determine in the AST given by Flake8 if a function has positional-only arguments.