Skip to content

Commit

Permalink
Remove L-value checking in cast_to_lvalue
Browse files Browse the repository at this point in the history
  • Loading branch information
hsfzxjy committed Feb 7, 2021
1 parent 55fbfb6 commit 8c801bd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lambdex/utils/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def is_lvalue(node: ast.AST) -> bool:

def cast_to_lvalue(node: ast.AST):
"""
Recursively set `ctx` to `Store()` on `node` and its children.
Recursively set `ctx` to `Store()` on `node` and its children. This
function assumes that `is_lvalue()` check has passed.
The behavior ony propagates down to children with type `ast.List`,
`ast.Tuple` and `ast.Starred`. e.g. name `attr` in `a[attr]` will
Expand All @@ -152,10 +153,9 @@ def cast_to_lvalue(node: ast.AST):
todo = deque([node])
while todo:
n = todo.popleft()
if 'ctx' in n._fields:
n.ctx = ast.Store()
if isinstance(n, (ast.List, ast.Tuple, ast.Starred)):
todo.extend(ast.iter_child_nodes(n))
n.ctx = ast.Store()
if isinstance(n, (ast.List, ast.Tuple, ast.Starred)):
todo.extend(ast.iter_child_nodes(n))

return node

Expand Down

0 comments on commit 8c801bd

Please sign in to comment.