Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement more flake8-bugbear rules #9410

Closed
2 tasks
mikaelarguedas opened this issue Jan 6, 2024 · 5 comments · Fixed by #9411
Closed
2 tasks

Implement more flake8-bugbear rules #9410

mikaelarguedas opened this issue Jan 6, 2024 · 5 comments · Fixed by #9411
Assignees
Labels
good first issue Good for newcomers rule Implementing or modifying a lint rule

Comments

@mikaelarguedas
Copy link
Contributor

(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.
@charliermarsh
Copy link
Member

Nice, we can definitely catch those in B035.

@charliermarsh charliermarsh added good first issue Good for newcomers rule Implementing or modifying a lint rule labels Jan 6, 2024
@charliermarsh charliermarsh self-assigned this Jan 6, 2024
@charliermarsh
Copy link
Member

I'm gonna do this for fun, and move the rule to B035.

@mikaelarguedas
Copy link
Contributor Author

Awesome thanks!

2 newbies questions:

  • Should this ticket stay opened for the implementation of B036 ?
  • How does the moving / equaling error codes work ? is there a track somewhere of error codes that are equivalent ? (losely related to my reflection for [Question] A status page for all implemented plugins and rules? #9354 where making equivalent rules visible could be a good first step)

@charliermarsh
Copy link
Member

@mikaelarguedas -- Ah yeah, I actually missed that second bullet. But I'm going to move that into #3758 and generalize the ticket since it's about a new rule.

We can rename rules and have them continue to work internally, so e.g. if folks have RUF011 as a # noqa or similar it will continue to work with a redirect. We have some notes on rule aliasing here (#2186), but we're planning to do a big overhaul of the rule categories and hierarchies some time this year anyway.

@mikaelarguedas
Copy link
Contributor Author

But I'm going to move that into #3758 and generalize the ticket since it's about a new rule.

👍

We can rename rules and have them continue to work internally, so e.g. if folks have RUF011 as a # noqa or similar it will continue to work with a redirect.

Great! Does this appear on the website in the category of the relevant flake8 plugin ?

We have some notes on rule aliasing here (#2186), but we're planning to do a big overhaul of the rule categories and hierarchies some time this year anyway.

❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants