Skip to content

False positive: SIM222 #3830

@AA-Turner

Description

@AA-Turner

Ruff 0.0.260

Reproducer:

(sphinx) PS I:\Development\sphinx> ruff -V                                                 
ruff 0.0.260
(sphinx) PS I:\Development\sphinx> type bug_sim222.py
a = 'foo'

if a == 'bar' and False:  # NoQA: SIM223
   pass

if 1 == 2 and False:  # NoQA: SIM223
   pass
(sphinx) PS I:\Development\sphinx> ruff --isolated --show-source --select SIM bug_sim222.py
bug_sim222.py:3:4: SIM222 [*] Use `True` instead of `... or True`
  |
3 | if a == 'bar' and False:  # NoQA: SIM223
  |    ^^^^^^^^^^^^^^^^^^^^ SIM222
  |
  = help: Replace with `True`

bug_sim222.py:6:4: SIM222 [*] Use `True` instead of `... or True`
  |
6 | if 1 == 2 and False:  # NoQA: SIM223
  |    ^^^^^^^^^^^^^^^^ SIM222
  |
  = help: Replace with `True`

Found 2 errors.
[*] 2 potentially fixable with the --fix option.
(sphinx) PS I:\Development\sphinx> 

Note that the # NoQA: SIM223 is intentional, this is from a 'TODO' part of a method.

In reducing the error case I wondered if the logic required a variable at all, and hence the second reprodcuer -- clearly this is statically false!

I don't have a guess as to what is causing this, sorry!

Thanks,
Adam

Metadata

Metadata

Assignees

No one assigned

    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