Skip to content

Commit

Permalink
Fix match subject ignoring redefinitions (#15306)
Browse files Browse the repository at this point in the history
Fixes #14746
  • Loading branch information
VincentVanlaer authored May 26, 2023
1 parent ac6dc18 commit da5dffc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions mypy/renaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
self.analyze_lvalue(lvalue)

def visit_match_stmt(self, s: MatchStmt) -> None:
s.subject.accept(self)
for i in range(len(s.patterns)):
with self.enter_block():
s.patterns[i].accept(self)
Expand Down
25 changes: 25 additions & 0 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -1933,3 +1933,28 @@ def match_stmt_error5(x: Optional[str]) -> None:
pass
nested()
[builtins fixtures/tuple.pyi]

[case testMatchSubjectRedefinition]
# flags: --allow-redefinition
def transform1(a: str) -> int:
...

def transform2(a: int) -> str:
...

def redefinition_good(a: str):
a = transform1(a)

match (a + 1):
case _:
...


def redefinition_bad(a: int):
a = transform2(a)

match (a + 1): # E: Unsupported operand types for + ("str" and "int")
case _:
...

[builtins fixtures/primitives.pyi]

0 comments on commit da5dffc

Please sign in to comment.