本文整理匯總了Python中_ast.Del方法的典型用法代碼示例。如果您正苦於以下問題:Python _ast.Del方法的具體用法?Python _ast.Del怎麽用?Python _ast.Del使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類_ast
的用法示例。
在下文中一共展示了_ast.Del方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: visit_attribute
# 需要導入模塊: import _ast [as 別名]
# 或者: from _ast import Del [as 別名]
def visit_attribute(self, node, parent):
"""visit an Attribute node by returning a fresh instance of it"""
context = _get_context(node)
if context == astroid.Del:
# FIXME : maybe we should reintroduce and visit_delattr ?
# for instance, deactivating assign_ctx
newnode = nodes.DelAttr(node.attr, node.lineno, node.col_offset,
parent)
elif context == astroid.Store:
newnode = nodes.AssignAttr(node.attr, node.lineno, node.col_offset,
parent)
# Prohibit a local save if we are in an ExceptHandler.
if not isinstance(parent, astroid.ExceptHandler):
self._delayed_assattr.append(newnode)
else:
newnode = nodes.Attribute(node.attr, node.lineno, node.col_offset,
parent)
newnode.postinit(self.visit(node.value, newnode))
return newnode
示例2: visit_name
# 需要導入模塊: import _ast [as 別名]
# 或者: from _ast import Del [as 別名]
def visit_name(self, node, parent):
"""visit a Name node by returning a fresh instance of it"""
context = _get_context(node)
# True and False can be assigned to something in py2x, so we have to
# check first the context.
if context == astroid.Del:
newnode = nodes.DelName(node.id, node.lineno, node.col_offset,
parent)
elif context == astroid.Store:
newnode = nodes.AssignName(node.id, node.lineno, node.col_offset,
parent)
elif node.id in CONST_NAME_TRANSFORMS:
newnode = nodes.Const(CONST_NAME_TRANSFORMS[node.id],
getattr(node, 'lineno', None),
getattr(node, 'col_offset', None), parent)
return newnode
else:
newnode = nodes.Name(node.id, node.lineno, node.col_offset, parent)
# XXX REMOVE me :
if context in (astroid.Del, astroid.Store): # 'Aug' ??
self._save_assignment(newnode)
return newnode
示例3: NAME
# 需要導入模塊: import _ast [as 別名]
# 或者: from _ast import Del [as 別名]
def NAME(self, node):
"""
Handle occurrence of Name (which can be a load/store/delete access.)
"""
# Locate the name in locals / function / globals scopes.
if isinstance(node.ctx, (ast.Load, ast.AugLoad)):
self.handleNodeLoad(node)
if (node.id == 'locals' and isinstance(self.scope, FunctionScope)
and isinstance(node.parent, ast.Call)):
# we are doing locals() call in current scope
self.scope.usesLocals = True
elif isinstance(node.ctx, (ast.Store, ast.AugStore)):
self.handleNodeStore(node)
elif isinstance(node.ctx, ast.Del):
self.handleNodeDelete(node)
else:
# must be a Param context -- this only happens for names in function
# arguments, but these aren't dispatched through here
raise RuntimeError("Got impossible expression context: %r" % (node.ctx,))
示例4: make_delete
# 需要導入模塊: import _ast [as 別名]
# 或者: from _ast import Del [as 別名]
def make_delete(i, bytecode):
logger.debug("Delete: \n%s", show_bytecode(bytecode))
op = bytecode[i][2]
if op == DELETE_SUBSCR:
i, subscr_expr = Statement.make_subscript(i, bytecode, context=_ast.Del())
return i, _ast.Delete([subscr_expr])
else:
i, attr_expr = Statement.make_expr(i, bytecode, context=_ast.Del())
return i, _ast.Delete([attr_expr])
return i, None
示例5: make_store_delete_slice
# 需要導入模塊: import _ast [as 別名]
# 或者: from _ast import Del [as 別名]
def make_store_delete_slice(i, bytecode, context=None):
op = bytecode[i][2]
is_delete = op in DELETE_SLICE_OPCODES
if context is None:
context = _ast.Store() if not is_delete else _ast.Del()
lhs_expr = None
if op in (STORE_SLICE_0, DELETE_SLICE_0):
i, lhs_expr = Statement.make_expr(i - 1, bytecode, context=context)
lhs_expr = _ast.Subscript(lhs_expr,
_ast.Slice(None, None, None),
_ast.Store())
elif op in (STORE_SLICE_1, STORE_SLICE_2, DELETE_SLICE_1, DELETE_SLICE_2):
i, index_expr = Statement.make_expr(i - 1, bytecode)
i, arr_expr = Statement.make_expr(i - 1, bytecode, context=context)
args = [None] * 3
index_index = 0 if op in (STORE_SLICE_1, DELETE_SLICE_1) else 1
args[index_index] = index_expr
lhs_expr = _ast.Subscript(arr_expr,
_ast.Slice(*args),
_ast.Store())
else:
i, end_index_expr = Statement.make_expr(i - 1, bytecode)
i, start_index_expr = Statement.make_expr(i - 1, bytecode)
i, arr_expr = Statement.make_expr(i - 1, bytecode, context=context)
lhs_expr = _ast.Subscript(arr_expr,
_ast.Slice(start_index_expr, end_index_expr, None),
_ast.Store())
if is_delete:
return i, _ast.Delete([lhs_expr])
else:
i, rhs_expr = Statement.make_expr(i - 1, bytecode)
return i, _ast.Assign([lhs_expr], rhs_expr)
示例6: visit_name
# 需要導入模塊: import _ast [as 別名]
# 或者: from _ast import Del [as 別名]
def visit_name(self, node: _ast.Name): # id, ctx
ctx = node.ctx.__class__
if ctx in (_ast.Param, _ast.Del):
return node.id
else:
if node.id in self.symbol_table:
return self.symbol_table[node.id]
if node.id in self.global_symbol_table:
return self.global_symbol_table[node.id]
raise NameError()