Skip to content

complex-if-statement-in-stub (PYI002) conflicts with if-with-same-arms (SIM114) #15153

@Avasam

Description

@Avasam

In python/typeshed#13309 I found that the following rules can be in conflict:

Example:

import sys

if sys.version_info >= (3, 11):  # SIM114
    OP_IGNORE_UNEXPECTED_EOF: int
elif sys.version_info >= (3, 8) and sys.platform == "linux":
    OP_IGNORE_UNEXPECTED_EOF: int
import sys

if sys.version_info >= (3, 11) or (sys.version_info >= (3, 8) and sys.platform == "linux"):  # PYI002
    OP_IGNORE_UNEXPECTED_EOF: int

What would the recommendation be here? Could either rule be adapted so they work together ?

In this specific case, granted that typeshed's oldest supported Python version is 3.8, this could be adapted to:

import sys

if sys.version_info >= (3, 11) or sys.platform == "linux":
    OP_IGNORE_UNEXPECTED_EOF: int

But the underlying issue still exists.


Ruff 0.8.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions