Skip to content

False positive of reportUnnecessaryComparison on match case with int(<float>) #11026

@q-wertz

Description

@q-wertz

Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues.

If you have a question about typing or a behavior that you’re seeing in Pyright (as opposed to a bug report or enhancement request), consider posting to the Pyright discussion forum.

Describe the bug

In the following code

sr = int(2.0e6)

match sr:
    case int(2.0e6):
        a = "asdf"
    case int(2.4e6):
        a = "cvbn"
    case _:
        raise ValueError

print(a)

a reportUnnecessaryComparison error is shown in strict mode (Playground).

As soon as it is replaced by integers directly the error is gone.

sr = 2000000

match sr:
    case 2000000:
        a = "asdf"
    case 2400000:
        a = "cvbn"
    case _:
        raise ValueError

print(a)

Not sure if some float/int thing I don't get right but I think it also should not fail in the first example.

Code or Screenshots
If possible, provide a minimal, self-contained code sample (surrounded by triple back ticks) to demonstrate the issue. The code should define or import all referenced symbols.

sr = int(2.0e6)

match sr:
    case int(2.0e6):
        a = "asdf"
    case int(2.4e6):
        a = "cvbn"
    case _:
        raise ValueError

print(a)

If your code relies on symbols that are imported from a third-party library, include the associated import statements and specify which versions of those libraries you have installed.

VS Code extension or command-line
Are you running pyright as a VS Code extension, a language server in another editor, integrated into Pylance, or the command-line tool? Which version?

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions