Skip to content

Commit

Permalink
Fix inference bug with If node
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelMarcelino committed Sep 22, 2022
1 parent d90cf6b commit 823f0d1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions py2many/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,12 @@ def _visit_val_branch(self, node: ast.If, ann, ann_node_id):
ann_node.annotation = ast.Name(id="None")
for n in node.orelse:
self.visit(n)
else:
node.test.annotation = ann
for n in node.body:
self.visit(n)
for n in node.orelse:
self.visit(n)

def _visit_none_branch(self, node: ast.If, ann, ann_node_id):
if self._is_optional(ann):
Expand All @@ -969,6 +975,12 @@ def _visit_none_branch(self, node: ast.If, ann, ann_node_id):
ann_node.annotation = ann.slice
for n in node.orelse:
self.visit(n)
else:
node.test.annotation = ann
for n in node.body:
self.visit(n)
for n in node.orelse:
self.visit(n)

def _is_optional(self, annotation):
is_optional = lambda x: get_id(x) == "Optional"
Expand Down

0 comments on commit 823f0d1

Please sign in to comment.