Skip to content

Commit

Permalink
Fix error location for class patterns (#15506)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Jun 23, 2023
1 parent 2d8ad8e commit c099b20
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/checkpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType:
name = type_info.type.str_with_options(self.options)
else:
name = type_info.name
self.msg.fail(message_registry.CLASS_PATTERN_TYPE_REQUIRED.format(name), o.class_ref)
self.msg.fail(message_registry.CLASS_PATTERN_TYPE_REQUIRED.format(name), o)
return self.early_non_match()

new_type, rest_type = self.chk.conditional_types_with_intersection(
Expand Down
20 changes: 20 additions & 0 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -1958,3 +1958,23 @@ def redefinition_bad(a: int):
...

[builtins fixtures/primitives.pyi]

[case testPatternMatchingClassPatternLocation]
# See https://github.com/python/mypy/issues/15496
from some_missing_lib import DataFrame, Series # type: ignore[import]
from typing import TypeVar

T = TypeVar("T", Series, DataFrame)

def f(x: T) -> None:
match x:
case Series() | DataFrame(): # type: ignore[misc]
pass

def f2(x: T) -> None:
match x:
case Series(): # type: ignore[misc]
pass
case DataFrame(): # type: ignore[misc]
pass
[builtins fixtures/primitives.pyi]

0 comments on commit c099b20

Please sign in to comment.