Skip to content

Commit

Permalink
allow redefinition of functions across match arms (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile authored Apr 25, 2023
1 parent e19886e commit f2671ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pyflakes/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
def getAlternatives(n):
if isinstance(n, ast.If):
return [n.body]
if isinstance(n, ast.Try):
elif isinstance(n, ast.Try):
return [n.body + n.orelse] + [[hdl] for hdl in n.handlers]
elif sys.version_info >= (3, 10) and isinstance(n, ast.Match):
return [mc.body for mc in n.cases]


FOR_TYPES = (ast.For, ast.AsyncFor)
Expand Down
11 changes: 11 additions & 0 deletions pyflakes/test/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,14 @@ def test_match_double_star(self):
case {'foo': k1, **rest}:
print(f'{k1=} {rest=}')
''')

def test_defined_in_different_branches(self):
self.flakes('''
def f(x):
match x:
case 1:
def y(): pass
case _:
def y(): print(1)
return y
''')

0 comments on commit f2671ff

Please sign in to comment.