MartinThoma / flake8-simplify

❄ A flake8 plugin that helps you to simplify code
MIT License
185 stars 19 forks source link

[Adjust Rule] SIM201 - SIM207 #13

Closed MartinThoma closed 3 years ago

MartinThoma commented 3 years ago

Desired change

Rules for reducing the usage of "not" should not be applied if an exception is raised if the condition applies.

Explanation

The pattern usually is:

if not condition:
    raise Exception("condition is not fulfilled but needs to be")

Example

if not (minimum < maximum):
    raise ValueError(f"minimum={minimum} needs to be smaller than maximum={maximum}")
MartinThoma commented 3 years ago

Blocked by https://github.com/MartinThoma/flake8-simplify/issues/21