Skip to content

[1.20] Regression on Mapping equality type narrowing #21385

@Dreamsorcerer

Description

@Dreamsorcerer

Bug Report

Report requested from #20726 (comment)

To Reproduce

from collections.abc import Mapping
x: Mapping[str, str]
assert x == {"a": "b"}
x["a"] = "foo"

Expected Behavior

mypy 1.19 produces an index error.
mypy 1.20 seems to incorrectly narrow the type to a dict and then allows the assignment, which may not actually work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions