Skip to content

Changed strict-equality behavior with dict/Mapping #16340

Closed
@JukkaL

Description

@JukkaL

When using mypy 1.6, this example produces no errors:

# mypy: strict-equality

from typing import Mapping

def f(x: dict[str, int | None], y: dict[str, str | None]) -> bool:
    return x == y

def g(x: Mapping[str, int], y: str) -> bool:
    return x == y

However, after #16237, it started generating these errors:

t.py:6: error: Non-overlapping equality check (left operand type: "dict[str, int | None]", right operand type: "dict[str, str | None]")  [comparison-overlap]
t.py:9: error: Non-overlapping equality check (left operand type: "Mapping[str, int]", right operand type: "str")  [comparison-overlap]

I'm not sure if the new behavior is better or not, but I suspect that the change in behavior may have been an unintended consequence of #16237, so it seems worth investigating what is going on.

cc @ilevkivskyi

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-overlapOverlapping equality check

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions