Implement more flake8-bugbear opinionated rules
- Dominant language
- Rust
- Stars
- 49.7k
- Forks
- 2.4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 458
Description
Picking up where https://github.com/charliermarsh/ruff/issues/2954 left off, there were a few opinionated (B9xx flake8-bugbear rules) checks left to be implemented in Ruff:
* [x] B901: Using `return x` in a generator function. _(Somewhat bad reasoning in flake8-bugbear description, talks about Python 2, see comment here https://github.com/charliermarsh/ruff/issues/2954#issuecomment-1441162976 around its utility.)_
- [x] B902: _Implemented as N804 and N805._
* [ ] B903: Use `collections.namedtuple` (or `typing.NamedTuple`) for data classes that only set attributes in an `__init__` method, and do nothing else. _(Probably should include dataclasses recommendation? NamedTuple injects extra tuple methods and is meant for backward compat, not a data class replacement. That's `dataclasses` nowadays.)_
* [ ] ~B906: `visit_` function with no further call to a `visit` function.~
- [ ] B907: Consider replacing f"'{foo}'" with f"{foo!r}" which is both easier to read and will escape quotes inside foo if that would appear.
- [x] B908: _Partly implemented as PT012_.
There's an open question on how these should be included, since it would deviate from flake8-bugbear to have these on by default just by turning on the rest of the bugbear rules (see comment https://github.com/charliermarsh/ruff/issues/2954#issuecomment-1483594606).
There's also one outstanding non-opinionated rule:
- [x] 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. _Implemented as BLE001._
- [x] B038: _Renamed to B909 in bugbear; implemented as B909 is Ruff._
Contributor guide
Research direction
Start by reviewing the linked issue and Ruff's existing implementations of B901, PT012, BLE001, and B909 to understand the rule structure. Resolve the inclusion policy for opinionated rules, then investigate B903 and B907; done means the selected checks are implemented consistently with Ruff's existing rules and their behavior is covered by the relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100