Skip to content

Wrong "Non-overlapping equality check" warning #12561

Closed
@rggjan

Description

@rggjan

Running this code:

from typing import Any, Callable


class Foo:
    def __init__(self, a: int) -> None:
        print(a)


def bar(f: Callable[[Any], Any]) -> None:
    if type(f) ==Foo:
        print("The same!")

    f(3)


bar(Foo)

with mypy 0.942 and "strict_equality" enabled leads to:

error: Non-overlapping equality check (left operand type: "Type[Callable[[Any], Any]]", right operand type: "Type[Foo]")

I think this is wrong, as clearly, mypy accepts Foo as a correct argument to bar, in which case checking if f inside the function is of type Foo should also be valid...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-callsFunction calls, *args, **kwargs, defaultstopic-overlapOverlapping equality check

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions