mypy icon indicating copy to clipboard operation
mypy copied to clipboard

numpy dtype Statement is unreachable with mypy 1.19.0

Open acabal33uab opened this issue 3 weeks ago • 1 comments

Bug Report When checking the type field of a dtype with match, mypy 1.19.0 complains sbout some cases with error: Statement is unreachable. It doesn't look like a numpy bug because swapping the order of the cases (eg. moving the int32 case to the top) it produces inconsistent results (eg. it generates 1 error instead of 2).

To Reproduce

import numpy as np


def f(dt: np.dtype) -> None:
    match dt.type:
        case np.float64:
            print("f")
        case np.int64:
            print("i")
        case np.int32:
            print("i")


dt: np.dtype = np.dtype(np.float64)
f(dt)

Expected Behavior

Mypy should not complain

Actual Behavior

kk.py:9: error: Statement is unreachable  [unreachable]
                print("i")
                ^~~~~~~~~~
kk.py:11: error: Statement is unreachable  [unreachable]
                print("i")
                ^~~~~~~~~~
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.19.0
  • Mypy command-line flags: mypy --warn-unreachable kk.py
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.14.0

acabal33uab avatar Dec 03 '25 15:12 acabal33uab

#20146 should fix this. This is a logic bug in how mypy treats match-case arms with value patterns.

sterliakov avatar Dec 03 '25 15:12 sterliakov