Skip to content

[1.20 regression] incorrect reachability for comparisons between set and frozenset #21143

Description

@hauntsaninja
def foo(x: frozenset[str], y: set[str]):
    if x == y:
        reveal_type(x)

With --warn-unreachable the reveal_type is marked as unreachable. This relates to new narrowing logic in mypy 1.20. An easy fix could be to mark frozenset as having a custom __eq__.

Activity

  1. ilevkivskyi commented on Apr 1, 2026

    @ilevkivskyi
    Member

    @hauntsaninja I think a proper fix would be to re-use all the special-casing from dangerous_comparison(). There is a whole bunch of special-casing for builtin/stdlib collections that reflects runtime behavior. Also keeping these two in sync would be generally beneficial.

  2. added 2 commits that reference this issue on Apr 2, 2026
    8451b92
    bdb0dd4
  3. added a commit that references this issue on Apr 5, 2026
    6fccffc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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