Latest Results
[`flake8-comprehensions`] NFKC-normalize keyword names in `C408` fix (#26813)
Python normalizes identifiers to NFKC, but does not normalize string
literals. The fix for `unnecessary-collection-call` (C408) reparses the
call with libcst, which — unlike Ruff's own parser — does not normalize
identifiers, and then emits the raw source text of each keyword argument
as a dictionary key. This changed the key at runtime: `dict(ℼ=3.14)` has
the key `π`, but was rewritten to `{"ℼ": 3.14}`.
Normalize the keyword name before quoting it, matching what
`fix::codemods` already does for qualified names built from libCST
nodes.
Fixes #16234
## Summary
Python normalizes identifiers to NFKC, but not string literals. The C408
fix
re-parses the call with libcst, and that parser has a particular quirk:
it does
not normalize (Ruff's own parser does). So libcst hands over the raw
source text
of the kwarg as the key.
`dict(ℼ=3.14)` has the key `π` at RUNTIME, but was rewritten to `{"ℼ":
3.14}` >
this changes the behavior.
My fix normalizes the kwarg name before quoting it. I'm not creating
anything
new, because `fix::codemods` already does the same thing.
I decided not to mark it as unsafe, because the C408 fix is already
unsafe. And
unlike B009/B010/B043 (string > identifier, where preserving the
behavior is
impossible), C408 goes identifier > string. So the correct key can be
computed :)
## Test Plan
- 4 new cases at the end of `C408.py`: `ℼ`→`π`, `ſ`→`s`, `𝕒`→`a`, plus
an ASCII control with no changes.
- The snapshot diff is essentially additive. No diagnostic was altered.
- The `allow_dict_calls_with_keyword_arguments` snapshot stayed INTACT.
- `cargo test -p ruff_linter`: 2811 passed, 0 failed :)
- `clippy --workspace --all-features -D warnings`: 100% clean.
`generate-all`: up-to-date. And `prek run -a`: 14/14.
Fixes #16234
---------
Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Latest Branches
0%
lerebear/push-xtqywqpsmllp 0%
lerebear/push-wrzqmxouryzx 0%
Jayashanker-Padishala:fix-27021-up040-typevar-default-order © 2026 CodSpeed Technology