def _delete_element(target, context, lineno, solver):
"""Remove (if needed) a target from the context
Cases:
- del var_name: remove its type mapping from the context directly.
- del subscript:
* Tuple/String --> Immutable. Raise exception.
* List/Dict --> Do nothing to the context.
"""
if isinstance(target, (ast.Tuple, ast.List)): # Multiple deletions
for elem in target.elts:
_delete_element(elem, context, lineno, solver)
elif isinstance(target, ast.Name):
context.delete_type(target.id)
elif isinstance(target, ast.Subscript):
expr.infer(target, context, solver)
indexed_type = expr.infer(target.value, context, solver)
solver.add(axioms.delete_subscript(indexed_type, solver.z3_types),
fail_message="Deletion in line {}".format(lineno))
elif isinstance(target, ast.Attribute):
raise NotImplementedError("Attribute deletion is not supported.")
评论列表
文章目录