Skip to content

False positive reportUnnecessaryComparison for ModuleType instance vs Module("typing") #10706

@AlexWaygood

Description

@AlexWaygood

Describe the bug
Pyright believes that the type Module("typing") and the type types.ModuleType do not overlap. But that's not true: the object stored in a scope under the name typing due to the statement import typing is an instance of types.ModuleType. This leads to false-positive reportUnnecessaryComparison diagnostics.

Code or Screenshots

import types
import typing

def f(x: types.ModuleType):
    if x is typing:  # Condition will always evaluate to False since the types "ModuleType" and "Module("typing")" have no overlap  (reportUnnecessaryComparison)
        print("found typing")

https://pyright-play.net/?pythonVersion=3.13&strict=true&enableExperimentalFeatures=true&code=JYWwDg9gTgLgBDAnmApgZwFCkrBzgB2A5hhgCYoBmclAFAB4BceqaAdALIRkCuANigAqyFAEpGGOFLjBq9GWhaEiE6WrhgohGLQBElCDwJklxXaIxA

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