Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix match subject ignoring redefinitions #15306

Merged
merged 1 commit into from May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions mypy/renaming.py
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
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]