Skip to content

Implement more flake8-bugbear rules #9410

@mikaelarguedas

Description

@mikaelarguedas

(B035 aka RUF011 implemented in bugbear PyCQA/flake8-bugbear#391)

  • B035: Found dict comprehension with a static key - either a constant value or variable not from the comprehension expression. This will result in a dict with a single key that was repeatedly overwritten.
bugbear version's catches more problematic cases
CONST_KEY_VAR = "KEY"

# bad
bad_const_key_var = {CONST_KEY_VAR: i for i in range(3)}

# bad - variabe not from generator
v3 = 1
bad_var_not_from_nested_tuple = {v3: k for k, (v1, v2) in {"a": (1, 2)}.items()}

RUF012 doesnt report any error

flake8-bugbear reports:

B035 Static key in dict comprehension 'CONST_KEY_VAR'.
B035 Static key in dict comprehension 'v3'.
  • B036: Found except BaseException: without re-raising (no raise in the top-level of the except block). This catches all kinds of things (Exception, SystemExit, KeyboardInterrupt...) and may prevent a program from exiting as expected.

Metadata

Metadata

Assignees

Labels

good first issueGood for newcomersruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions