Skip to content

[Feature Request] Guard against == for (sequence of) float comparison #14220

@DanielYang59

Description

@DanielYang59

Feature request: Guard against == for float comparison

I'm not sure if this is doable from ruff's side as this might need optional static typing (mypy for example).

I could think of the following cases where == should be discouraged (or avoided altogether as it's pretty unreliable, I cannot think of much use cases we need such comparison):

# directly compare floats
1.0 == 1.0 + 1E-8

# floats generated by evaluation
x = 1 / 3
if x == 0.333:
    do something

# sequence of floats
[1.0, ] == [1.0 + 1E-8, ]

# use `in` to check membership
0.0 in [0, 1, 2]

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint ruletype-inferenceRequires more advanced type inference.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions