-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
F601: Repeated int keys not detected with booleans #12772
Comments
I think this makes sense because I'd be wary of any side effects of this change because a lot of rules utilize the |
I'm really surprised by this. @AlexWaygood or @carljm is this specified anywhere? |
Yeah, this is a really common footgun. (I think everybody agrees that it's terrible, but it's because early versions of Python didn't have a |
Okay maybe not an FAQ, but there's some specification of this here: https://docs.python.org/3/library/stdtypes.html#mapping-types-dict |
Ok thanks! |
Just to clarify, is the decision that we should include this identification as part of I could imagine both situations where we would want to distinguish between What about making a custom equivalence method on the |
Yeah, not quiet sure to be honest. Maybe @charliermarsh has a better sense for it. Overall, the idea of |
Yeah, I think it needs to be a more localized change. I don’t think those AST nodes should compare as equal. |
The multi-value-repeated-key-literal (F601) rule doesn't detect when a key has been duplicated for
True
andFalse
boolean when they duplicate a matching int literal. This is also true for the reverse where an int literal duplicates an existing bool key. This was found with ruff0.5.7
and Python3.12.2
.Ruff detects the int literal repetition, but misses the bool repetition.
This state of this dict is ultimately
{1: 'ghi', 0: 'baz'}
. I haven't found a stated guarantee thatTrue
is always1
, andFalse
is always0
, but it appears that they are. The only thing I've seen related is this note in Boolean type - bool:The text was updated successfully, but these errors were encountered: