-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 opinionated rules #3758
Comments
|
Since then some new rule apppeared
|
Good first issues for anyone interested :) |
Another 2 rules appeared in flake8-bugbear:
|
B037 is already implemented as PLE0100, @charliermarsh maybe we should consider migrating PLE0100 to B037 though? |
@Skylion007 - Yes good call -- I prefer indexing under bugbear over Pylint since it's more popular for Ruff users. I'll add a note to the 0.2.0 release list. |
@zanieb Was this closed on purpose ? I'm under the impression that some rules listed here are not part of ruff yet: |
@mikaelarguedas - I think it was an oversight, but I'll leave it to @zanieb to confirm in the AM. |
I think B036 is covered/aliased by BLE001. |
@charliermarsh @zanieb friendly 🛎️ if it was closed by mistake, is it possible to reopen and update according to current state ? Current state: |
Will update the list, thanks. |
Updated. We do actually have B038 (which bugbear moved to B909). |
## Summary This PR implements the rule B901, which is part of the opinionated rules of `flake8-bugbear`. This rule seems to be desired in `ruff` as per #3758 and #2954 (comment). ## Test Plan As this PR was made closely following the [CONTRIBUTING.md](https://github.com/astral-sh/ruff/blob/8a25531a7144fd4a6b62c54efde1ef28e2dc18c4/CONTRIBUTING.md), it tests using the snapshot approach, that is described there. ## Sources The implementation is inspired by [the original implementation in the `flake8-bugbear` repository](https://github.com/PyCQA/flake8-bugbear/blob/d1aec4cbef7c4a49147c428b7e4a97e497b5d163/bugbear.py#L1092). The error message and [test file](https://github.com/PyCQA/flake8-bugbear/blob/d1aec4cbef7c4a49147c428b7e4a97e497b5d163/tests/b901.py) where also copied from there. The documentation I came up with on my own and needs improvement. Maybe the example given in #2954 (comment) could be used, but maybe they are too complex, I'm not sure. ## Open Questions - [ ] Documentation. (See above.) - [x] Can I access the parent in a visitor? The [original implementation](https://github.com/PyCQA/flake8-bugbear/blob/d1aec4cbef7c4a49147c428b7e4a97e497b5d163/bugbear.py#L1100) references the `yield` statement's parent to check if it is an expression statement. I didn't find a way to do this in `ruff` and used the `is_expresssion_statement` field on the visitor instead. What are your thoughts on this? Is it possible and / or desired to access the parent node here? - [x] Is `Option::is_some(...)` -> `...unwrap()` the right thing to do? Referring to [this piece of code](https://github.com/tobb10001/ruff/blob/9d5a280f71103ef33df5676d00a6c68c601261ac/crates/ruff_linter/src/rules/flake8_bugbear/rules/return_x_in_generator.rs?plain=1#L91-L96). From my understanding, the `.unwrap()` is safe, because it is checked that `return_` is not `None`. However, I feel like I missed a more elegant solution that does both in one. ## Other I don't know a lot about this rule, I just implemented it because I found it in a https://github.com/astral-sh/ruff/labels/good%20first%20issue. I'm new to Rust, so any constructive critisism is appreciated. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
This issue says that |
Interesting task,can I help? |
Picking up where #2954 left off, there were a few opinionated (B9xx flake8-bugbear rules) checks left to be implemented in Ruff:
return x
in a generator function. (Somewhat bad reasoning in flake8-bugbear description, talks about Python 2, see comment here Update bugbear #2954 (comment) around its utility.)collections.namedtuple
(ortyping.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'sdataclasses
nowadays.)B906:visit_
function with no further call to avisit
function.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 #2954 (comment)).
There's also one outstanding non-opinionated rule:
The text was updated successfully, but these errors were encountered: