MartinThoma / flake8-scream

β„οΈπŸ™€ Flake8 plugin that contains rules which do have known false-positives - it might still be useful for a one-time run

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PyPI version Code on Github Actions Status Code style: black

flake8-scream

A flake8 plugin that helps you scream your code.

Rules

  • 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)

Disabling Rules

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

Examples

SCR119

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:

SCR902

# 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.

SCR903

# 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.

About

β„οΈπŸ™€ Flake8 plugin that contains rules which do have known false-positives - it might still be useful for a one-time run

License:MIT License


Languages

Language:Python 97.7%Language:Makefile 2.3%