GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [2.2 regression] unreachable code regression with custom equality enum membership check · Issue #21703 · python/mypy

[2.2 regression] unreachable code regression with custom equality enum membership check #21703

New issue
Copy link
New issue
Copy link
Closed
#21706
Closed
[2.2 regression] unreachable code regression with custom equality enum membership check#21703
#21706
Copy link
Labels
bugmypy got something wrong

Description

@blbelew
blbelew
opened on Jul 8, 2026
Issue body actions

Bug Report

Mypy 2.2.0 introduced a regression from 2.1.0 with equality comparisons with custom integer enums.

Using the config option warn_unreachable = True, the following code checks successfully in mypy 2.1.0, but under mypy 2.2.0 fails with

test.py:23: error: Statement is unreachable  [unreachable]

despite the code actually hitting this path at runtime and printing "Success".

To Reproduce

#!/usr/bin/env python3
import enum
import sys
import typing

class E(enum.Enum):
    foo = 1
    bar = 2

    def __int__(self) -> int:
        return int(self.value)

    def __eq__(self, other: typing.Any) -> bool:
        return bool(int(self) == other)

class Test:
    def __init__(self) -> None:
        self.val: int  = 1

t = Test()

if t.val in [E.foo, E.bar]:
    print("success")
    sys.exit(0)
print("fail")
sys.exit(1)

Your Environment

  • Mypy version used: 2.2.0
  • Mypy command-line flags: mypy test.py
  • Mypy configuration options from mypy.ini (and other config files): warn_unreachable = True
  • Python version used: 3.11

Activity

  1. blbelew
    added
    bugmypy got something wrong
    on Jul 8, 2026
  2. blbelew
    changed the title [-]unreachable code regression with mpy 2.2.0 due to integer enum comparisons[/-] [+]unreachable code regression with mypy 2.2.0 due to integer enum comparisons[/+] on Jul 8, 2026
  3. hauntsaninja
    changed the title [-]unreachable code regression with mypy 2.2.0 due to integer enum comparisons[/-] [+][2.2 regression] unreachable code regression with custom equality enum[/+] on Jul 8, 2026
  4. hauntsaninja
    changed the title [-][2.2 regression] unreachable code regression with custom equality enum[/-] [+][2.2 regression] unreachable code regression with custom equality enum membership check[/+] on Jul 8, 2026
  5. hauntsaninja commented on Jul 8, 2026

    @hauntsaninja
    hauntsaninja
    on Jul 8, 2026
    Collaborator
    More actions

    Thanks for the report! Fix in #21706

    Reacted by Brandon Belew
  6. hauntsaninja
    closed this as completedin #21706on Jul 8, 2026
  7. dabreadman
    added a commit that references this issue on Jul 8, 2026

    Fix custom equality handling for membership narrowing in static conta…

    This issue will close once commit 77ccc7a is merged into the 'master' branch.
    77ccc7a
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

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.