Skip to content

Commit

Permalink
Fix bug in assignments (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlatr authored Aug 22, 2023
1 parent b212a3b commit f53330b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion beniget/beniget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ def visit_Destructured(self, node):
tmp_store, elt.ctx = elt.ctx, tmp_store
self.visit(elt)
tmp_store, elt.ctx = elt.ctx, tmp_store
elif isinstance(elt, (ast.Subscript, ast.Starred)):
elif isinstance(elt, (ast.Subscript, ast.Starred, ast.Attribute)):
self.visit(elt)
elif isinstance(elt, (ast.List, ast.Tuple)):
self.visit_Destructured(elt)
Expand Down
39 changes: 38 additions & 1 deletion tests/test_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,44 @@ class Attr(Attr):pass
['Attr -> (Attr -> (Attr -> ()))',
'Visitor -> ()'])
self.assertEqual(c.dump_chains(node.body[-1]), ['Attr -> ()'])


@skipIf(sys.version_info < (3, 0), 'Python 3 syntax')
def test_star_assignment(self):
code = '''
curr, *parts = [1,2,3]
while curr:
print(curr)
if parts:
curr, *parts = parts
else:
break
'''
self.checkChains(code, ['curr -> (curr -> (), curr -> (Call -> ()))',
'parts -> (parts -> (), parts -> ())']*2)

@skipIf(sys.version_info < (3, 0), 'Python 3 syntax')
def test_star_assignment_nested(self):
code = '''
(curr, *parts),i = [1,2,3],0
while curr:
print(curr)
if parts:
(curr, *parts),i = parts,i
else:
break
'''
self.checkChains(code, ['curr -> (curr -> (), curr -> (Call -> ()))',
'parts -> (parts -> (), parts -> (Tuple -> ()))',
'i -> (i -> (Tuple -> ()))']*2)

def test_attribute_assignment(self):
code = "d=object();d.name,x = 't',1"
self.checkChains(code, ['d -> (d -> (Attribute -> ()))',
'x -> ()'])

def test_call_assignment(self):
code = "NameError().name = 't'"
self.checkChains(code, [])

@skipIf(sys.version_info < (3, 0), 'Python 3 syntax')
def test_annotation_uses_class_level_name(self):
Expand Down

0 comments on commit f53330b

Please sign in to comment.