Skip to content

Implement flake8-simplify #998

@charliermarsh

Description

@charliermarsh

Python-specific rules:

  • SIM101 ("Multiple isinstance-calls which can be merged into a single call by using a tuple as a second argument")
  • SIM105 ("Use 'contextlib.suppress(...)' instead of try-except-pass")
  • SIM107 ("Don't use return in try/except and finally ")
  • SIM108 ("Use the ternary operator if it's reasonable ")
  • SIM109 ("Use a tuple to compare a value against multiple values")
  • SIM110 ("Use any(...) ")
  • SIM111 ("Use all(...)")
  • SIM113 ("Use enumerate instead of manually incrementing a counter")
  • SIM114 ("Combine conditions via a logical or to prevent duplicating code")
  • SIM115 ("Use context handler for opening files")
  • SIM116 ("Use a dictionary instead of many if/else equality checks")
  • SIM117 ("Merge with-statements that use the same scope")

Simplifying Comparisons:

  • SIM201 ("Use 'a != b' instead of 'not a == b'")
  • SIM202 ("Use 'a == b' instead of 'not a != b'")
  • SIM203 ("Use 'a not in b' instead of 'not (a in b)'")
  • SIM208 ("Use 'a' instead of 'not (not a)'")
  • SIM210 ("Use 'bool(a)' instead of 'True if a else False'")
  • SIM211 ("Use 'not a' instead of 'False if a else True'")
  • SIM212 ("Use 'a if a else b' instead of 'b if not a else a'")
  • SIM220 ("Use 'False' instead of 'a and not a'")
  • SIM221 ("Use 'True' instead of 'a or not a'")
  • SIM222 ("Use 'True' instead of '... or True'")
  • SIM223 ("Use 'False' instead of '... and False'")
  • SIM300 ("Use 'age == 42' instead of '42 == age'")

Simplifying usage of dictionaries:

  • SIM401 ("Use 'a_dict.get(key, "default_value")' instead of an if-block")
  • SIM118 ("Use 'key in dict' instead of 'key in dict.keys()'")

General Code Style:

  • SIM102 ("Use a single if-statement instead of nested if-statements")
  • SIM103 ("Return the boolean condition directly")
  • SIM112 ("Use CAPITAL environment variables")

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerspluginImplementing a known but unsupported plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions