Skip to content

Commit f2671ff

Browse files
authored
allow redefinition of functions across match arms (#772)
1 parent e19886e commit f2671ff

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pyflakes/checker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
def getAlternatives(n):
3030
if isinstance(n, ast.If):
3131
return [n.body]
32-
if isinstance(n, ast.Try):
32+
elif isinstance(n, ast.Try):
3333
return [n.body + n.orelse] + [[hdl] for hdl in n.handlers]
34+
elif sys.version_info >= (3, 10) and isinstance(n, ast.Match):
35+
return [mc.body for mc in n.cases]
3436

3537

3638
FOR_TYPES = (ast.For, ast.AsyncFor)

pyflakes/test/test_match.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,14 @@ def test_match_double_star(self):
8181
case {'foo': k1, **rest}:
8282
print(f'{k1=} {rest=}')
8383
''')
84+
85+
def test_defined_in_different_branches(self):
86+
self.flakes('''
87+
def f(x):
88+
match x:
89+
case 1:
90+
def y(): pass
91+
case _:
92+
def y(): print(1)
93+
return y
94+
''')

0 commit comments

Comments
 (0)