Skip to content

Commit eb0cf8a

Browse files
committed
Handle match case defines
1 parent 222ab20 commit eb0cf8a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pylint/checkers/variables.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,12 @@ def _inferred_to_define_name_raise_or_return(
674674
if isinstance(node, (nodes.With, nodes.For, nodes.While)):
675675
return NamesConsumer._defines_name_raises_or_returns_recursive(name, node)
676676

677+
if isinstance(node, nodes.Match):
678+
return all(
679+
NamesConsumer._defines_name_raises_or_returns_recursive(name, case)
680+
for case in node.cases
681+
)
682+
677683
if not isinstance(node, nodes.If):
678684
return False
679685

@@ -723,6 +729,7 @@ def _branch_handles_name(self, name: str, body: Iterable[nodes.NodeNG]) -> bool:
723729
nodes.With,
724730
nodes.For,
725731
nodes.While,
732+
nodes.Match,
726733
),
727734
)
728735
and self._inferred_to_define_name_raise_or_return(name, if_body_stmt)
@@ -975,6 +982,11 @@ def _defines_name_raises_or_returns_recursive(
975982
and NamesConsumer._defines_name_raises_or_returns_recursive(name, stmt)
976983
):
977984
return True
985+
if isinstance(stmt, nodes.Match):
986+
return all(
987+
NamesConsumer._defines_name_raises_or_returns_recursive(name, case)
988+
for case in stmt.cases
989+
)
978990
return False
979991

980992
@staticmethod

0 commit comments

Comments
 (0)