Repository navigation
Commit 8c244e5
## Summary
Documents that `map` objects and generator expressions are not
interchangeable
when the mapped expression raises, which is a known source of false
positives
for `unnecessary-map` (`C417`).
Once an exception propagates out of a generator, the generator is closed
and
every later `next()` call raises `StopIteration`. A `map` object has no
frame to
close, so a caller that handles the exception can keep iterating. Code
that
relies on this - for example, collecting every element that converts
successfully and reporting all failures at the end, rather than stopping
at the
first one - behaves differently after `C417`'s fix is applied.
As discussed in the issue, there isn't a good way for Ruff to detect
this
situation and suppress the diagnostic, so this adds a `## Known
problems`
section describing the difference and notes it under `## Fix safety` as
an
additional reason the fix is unsafe.
Docs-only; no behavior change.
Closes #27304
## Test Plan
`cargo dev generate-all`, plus `cargo nextest run -p ruff_linter -p
ruff_dev`
and `cargo clippy -p ruff_linter --all-targets -- -D warnings` to
confirm the
doc comment still builds and no generated artifact is stale.
---------
Co-authored-by: Brent Westbrook <[email protected]>
1 parent 5edf5a1 commit 8c244e5
1 file changed
Lines changed: 27 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
45 | 69 | | |
46 | | - | |
47 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
48 | 73 | | |
49 | 74 | | |
50 | 75 | | |
| |||
0 commit comments