Skip to content

Detect repeated signed and complex dictionary keys - #26007

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/f601-numeric-keys
Jun 15, 2026
Merged

Detect repeated signed and complex dictionary keys#26007
charliermarsh merged 1 commit into
mainfrom
charlie/f601-numeric-keys

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

F601 hashes dictionary keys with HashableExpr, but it only reported duplicate literal AST nodes, tuples, and f-strings. Signed numbers and constructed complex numbers are represented as unary or binary expressions, so the numeric-key equivalences added in #25982 were order-dependent:

{False: 1, -0: 2}  # missed
{-0: 1, False: 2}  # reported

This recognizes signed numeric and constructed complex expressions as literal keys without treating arbitrary unary or binary expressions as literals. F601 now reports the later key in either order for both False/-0 and True/1 + 0j.

@charliermarsh
charliermarsh force-pushed the charlie/f601-numeric-keys branch from 1cba3b6 to 79e3a8c Compare June 15, 2026 15:03
@charliermarsh
charliermarsh changed the base branch from main to charlie/hash June 15, 2026 15:03
@astral-sh-bot

astral-sh-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@charliermarsh
charliermarsh marked this pull request as ready for review June 15, 2026 17:27
@charliermarsh charliermarsh added the bug Something isn't working label Jun 15, 2026
@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre June 15, 2026 17:27
Base automatically changed from charlie/hash to main June 15, 2026 19:17
@charliermarsh
charliermarsh force-pushed the charlie/f601-numeric-keys branch 2 times, most recently from 7d15c18 to cb45445 Compare June 15, 2026 19:23
@charliermarsh
charliermarsh enabled auto-merge (squash) June 15, 2026 19:23
@charliermarsh
charliermarsh force-pushed the charlie/f601-numeric-keys branch from cb45445 to ef7f8c9 Compare June 15, 2026 19:28
@charliermarsh
charliermarsh merged commit 8ec809c into main Jun 15, 2026
44 checks passed
@charliermarsh
charliermarsh deleted the charlie/f601-numeric-keys branch June 15, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants