Skip to content

Commit c099b20

Browse files
authored
1 parent 2d8ad8e commit c099b20

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

mypy/checkpattern.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType:
468468
name = type_info.type.str_with_options(self.options)
469469
else:
470470
name = type_info.name
471-
self.msg.fail(message_registry.CLASS_PATTERN_TYPE_REQUIRED.format(name), o.class_ref)
471+
self.msg.fail(message_registry.CLASS_PATTERN_TYPE_REQUIRED.format(name), o)
472472
return self.early_non_match()
473473

474474
new_type, rest_type = self.chk.conditional_types_with_intersection(

test-data/unit/check-python310.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,3 +1958,23 @@ def redefinition_bad(a: int):
19581958
...
19591959

19601960
[builtins fixtures/primitives.pyi]
1961+
1962+
[case testPatternMatchingClassPatternLocation]
1963+
# See https://github.com/python/mypy/issues/15496
1964+
from some_missing_lib import DataFrame, Series # type: ignore[import]
1965+
from typing import TypeVar
1966+
1967+
T = TypeVar("T", Series, DataFrame)
1968+
1969+
def f(x: T) -> None:
1970+
match x:
1971+
case Series() | DataFrame(): # type: ignore[misc]
1972+
pass
1973+
1974+
def f2(x: T) -> None:
1975+
match x:
1976+
case Series(): # type: ignore[misc]
1977+
pass
1978+
case DataFrame(): # type: ignore[misc]
1979+
pass
1980+
[builtins fixtures/primitives.pyi]

0 commit comments

Comments
 (0)