ruff/crates/ruff_linter/resources/test/fixtures/flake8_bugbear
Bhuminjay Soni c722f498fe
[`flake8-bugbear`] Catch `yield` expressions within other statements (`B901`) (#21200)
## Summary

This PR re-implements [return-in-generator
(B901)](https://docs.astral.sh/ruff/rules/return-in-generator/#return-in-generator-b901)
for async generators as a semantic syntax error. This is not a syntax
error for sync generators, so we'll need to preserve both the lint rule
and the syntax error in this case.

It also updates B901 and the new implementation to catch cases where the
generator's `yield` or `yield from` expression is part of another
statement, as in:

```py
def foo():
    return (yield)
```

These were previously not caught because we only looked for
`Stmt::Expr(Expr::Yield)` in `visit_stmt` instead of visiting `yield`
expressions directly. I think this modification is within the spirit of
the rule and safe to try out since the rule is in preview.

## Test Plan

<!-- How was it tested? -->
I have written tests as directed in #17412

---------

Signed-off-by: 11happy <soni5happy@gmail.com>
Signed-off-by: 11happy <bhuminjaysoni@gmail.com>
Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
2025-12-03 12:05:15 -05:00
..
B002.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B003.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B004.py [`ruff`] Fix B004 to skip invalid hasattr/getattr calls (#20486) 2025-09-19 13:44:42 -05:00
B005.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B006_1.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B006_1.pyi [`flake8-bugbear`] - do not run `mutable-argument-default` on stubs (`B006`) (#14058) 2024-11-02 22:48:48 -04:00
B006_2.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B006_3.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B006_4.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B006_5.py Ensure that B006 autofixes are inserted after imports (#7629) 2023-09-27 01:26:29 +00:00
B006_6.py Ensure that B006 autofixes are inserted after imports (#7629) 2023-09-27 01:26:29 +00:00
B006_7.py Ensure that B006 autofixes are inserted after imports (#7629) 2023-09-27 01:26:29 +00:00
B006_8.py [`flake8-bugbear`] Treat `raise NotImplemented`-only bodies as stub functions (#10990) 2024-04-17 14:06:40 +00:00
B006_9.py [`flake8-bugbear`] Include certain guaranteed-mutable expressions: tuples, generators, and assignment expressions (`B006`) (#20024) 2025-10-03 09:29:36 -05:00
B006_B008.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B006_extended.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B007.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B008_extended.py [`flake8-bugbear`] Exempt `NewType` calls where the original type is immutable (`B008`) (#15765) 2025-01-29 10:26:17 +00:00
B009_B010.py [`flake8-bugbear`] Mark fix as unsafe for non-NFKC attribute names (`B009`, `B010`) (#21131) 2025-11-03 14:45:23 +00:00
B011.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B012.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B013.py [flake8-bugbear] Allow singleton tuples with starred expressions in B013 (#12484) 2024-07-24 15:19:30 +02:00
B014.py Insert necessary padding in B014 fixes (#7699) 2023-09-28 21:11:09 +00:00
B015.ipynb Avoid `B015`,`B018` for last expression in a cell (#8815) 2023-11-22 15:33:23 +00:00
B015.py [flake8_bugbear] message based on expression location [B015] (#12944) 2024-08-17 13:54:19 +02:00
B016.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B017_0.py [`flake8-bugbear`] Fix B017 false negatives for keyword exception arguments (#19217) 2025-07-11 16:43:09 +00:00
B017_1.py [`flake8-bugbear`] Support non-context-manager calls in `B017` (#19063) 2025-07-08 15:04:55 -04:00
B018.ipynb Avoid `B015`,`B018` for last expression in a cell (#8815) 2023-11-22 15:33:23 +00:00
B018.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B019.py Improve handling of metaclasses in various linter rules (#12579) 2024-07-30 14:48:36 +01:00
B020.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B021.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B022.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B023.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B024.py Ignore non-abstract class attributes when enforcing B024 (#11210) 2024-04-30 09:01:08 -07:00
B025.py Improve error messages for except* (B025, B029, B030, B904) #14791 (#14815) 2024-12-08 17:37:34 +00:00
B026.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B027.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B027.pyi Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B028.py [`flake8-bugbear`] Ignore `B028` if `skip_file_prefixes` is present (#18047) 2025-05-12 17:06:51 -05:00
B029.py Improve error messages for except* (B025, B029, B030, B904) #14791 (#14815) 2024-12-08 17:37:34 +00:00
B030.py Improve error messages for except* (B025, B029, B030, B904) #14791 (#14815) 2024-12-08 17:37:34 +00:00
B031.py Fix F701 to F707 errors in tests (#19125) 2025-07-04 13:43:18 -05:00
B032.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B033.py Detect items that hash to same value in duplicate sets (#14064) 2024-11-03 18:49:11 +00:00
B034.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
B035.py Recategorize `static-key-dict-comprehension` from `RUF011` to `B035` (#9428) 2024-02-01 13:35:02 -06:00
B039.py [`flake8-bugbear`] Fix `mutable-contextvar-default (B039)` to resolve annotated function calls properly (#14532) 2024-11-23 21:29:25 -05:00
B039_extended.py [`flake8-bugbear`] Implement mutable-contextvar-default (B039) (#12113) 2024-07-01 01:55:49 +00:00
B901.py [`flake8-bugbear`] Catch `yield` expressions within other statements (`B901`) (#21200) 2025-12-03 12:05:15 -05:00
B904.py Improve error messages for except* (B025, B029, B030, B904) #14791 (#14815) 2024-12-08 17:37:34 +00:00
B905.py [`flake8-bugbear`] Skip `B905` and `B912` if <2 iterables and no starred arguments (#20998) 2025-10-20 18:35:32 -05:00
B909.py Fix false positive in for mutations in return statements (B909) (#18408) 2025-06-13 10:39:55 -04:00
B911.py [`flake8-bugbear`] `itertools.batched()` without explicit `strict` (`B911`) (#14408) 2024-12-10 08:39:46 +00:00
B912.py [`flake8-bugbear`] Skip `B905` and `B912` if <2 iterables and no starred arguments (#20998) 2025-10-20 18:35:32 -05:00
class_as_data_structure.py [`flake8-bugbear`] Do not raise error if keyword argument is present and target-python version is less or equals than 3.9 (`B903`) (#15549) 2025-01-17 12:48:14 +01:00