Skip to content

F601: Duplicated keys with different parenthesisation fixed incorrectly #4897

@addisoncrump

Description

@addisoncrump

This is a case which I believe is potentially indicative of other bugs with the F601 fix.

Duplicated keys are merged by Ruff in the case of equal values, but the method by which this is done leads to a strange error in the case of different parenthesisation:

t={"x":"test123", "x":("test123")}

And the applied diff:

Fixed source has a syntax error where the source document does not. This is a bug in one of the generated fixes:
<filename>:1:17: E999 SyntaxError: unexpected token ')'
  |
1 | t={"x":"test123")}
  |                 ^ E999
  |


Last generated fixes:
<filename>:1:19: F601 [*] Dictionary key literal `"x"` repeated
  |
1 | t={"x":"test123", "x":("test123")}
  |                   ^^^ F601
  |
  = help: Remove repeated key literal `"x"`

ℹ Suggested fix
1   |-t={"x":"test123", "x":("test123")}
  1 |+t={"x":"test123")}


Source with applied fixes:
t={"x":"test123")}

Discovered by #4822.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixesRelated to suggested fixes for violations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions