Found a strange bug today: https://mypy-play.net/?mypy=master&python=3.11&gist=5069b99b248041428036a717e52a3476
from pandas import DataFrame, Series
from typing import TypeVar
T = TypeVar("T", Series, DataFrame)
def f(x: T) -> None:
match x:
case Series() | DataFrame(): # type: ignore[misc] # ignore does not work!
pass
case _:
pass
This makes mypy emit main.py: error: Expected type in class pattern; found "Any" [misc] without any line number. Adding the # type:ignore[misc] statement ends up not doing anything. I think it is because both Series and DataFrame are of Any-type (not using pandas-stubs here since it still raises too many issues)
Your Environment
- Mypy version used: 1.4.0
- Python version used: 3.11