Skip to content

PLC0208 false positive when a set contains equal values of different types #14049

@dscorbett

Description

@dscorbett

The fix for iteration-over-set (PLC0208) has false positives which change behavior. It intentionally ignores sets that contain duplicates, but when detecting duplicates it assumes that literals of different types are never equal. That is not true; for example, False == 0, so {False, 0} contains a duplicate and is actually equal to {False}.

$ ruff --version
ruff 0.7.2

$ cat plc0208.py
for x in {False, 0, 0.0, 0j, True, 1, 1.0}:
    print(x)

$ python plc0208.py 
False
True

$ ruff check --isolated --select PLC0208 plc0208.py --fix
Found 1 error (1 fixed, 0 remaining).

$ cat plc0208.py
for x in (False, 0, 0.0, 0j, True, 1, 1.0):
    print(x)

$ python plc0208.py
False
0
0.0
0j
True
1
1.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions