本文整理匯總了Python中ast.Delete方法的典型用法代碼示例。如果您正苦於以下問題:Python ast.Delete方法的具體用法?Python ast.Delete怎麽用?Python ast.Delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ast
的用法示例。
在下文中一共展示了ast.Delete方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: onelinerize
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Delete [as 別名]
def onelinerize(original):
# original :: string
# :: string
t = ast.parse(original)
table = symtable.symtable(original, '<string>', 'exec')
original = original.strip()
# If there's only one line anyways, be lazy
if len(original.splitlines()) == 1 and \
len(t.body) == 1 and \
type(t.body[0]) in (ast.Delete, ast.Assign, ast.AugAssign, ast.Print,
ast.Raise, ast.Assert, ast.Import, ast.ImportFrom,
ast.Exec, ast.Global, ast.Expr, ast.Pass):
return original
return get_init_code(t, table)
示例2: test_delete
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Delete [as 別名]
def test_delete(self):
self.stmt(ast.Delete([]), "empty targets on Delete")
self.stmt(ast.Delete([None]), "None disallowed")
self.stmt(ast.Delete([ast.Name("x", ast.Load())]),
"must have Del context")
示例3: p_del_stmt
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Delete [as 別名]
def p_del_stmt(p):
'''del_stmt : DEL exprlist'''
# 1 2
ctx_to_store(p[2], ast.Del) # interesting fact: evaluating Delete nodes with ctx=Store() causes a segmentation fault in Python!
if isinstance(p[2], ast.Tuple) and not p[2].paren:
p[0] = ast.Delete(p[2].elts, rule=inspect.currentframe().f_code.co_name, **p[1][1])
else:
p[0] = ast.Delete([p[2]], rule=inspect.currentframe().f_code.co_name, **p[1][1])
# pass_stmt: 'pass'
示例4: delete_statement
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Delete [as 別名]
def delete_statement(d: ast.Delete):
return "".join(f"delete {find(target)};" for target in d.targets)
示例5: translate_assign
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Delete [as 別名]
def translate_assign(self, exp, visible=True):
if len(exp) != 3:
raise MochiSyntaxError(exp, self.filename)
left = exp[1]
left_type = type(left)
if left_type is Symbol:
targets = [self.create_assign_target(left)]
ref_symbol = left
if not visible:
self.hidden_vars.append(ref_symbol.name)
elif issequence_except_str(left):
targets = [self.create_assign_targets(left)]
ref_symbol = NONE_SYM
else:
raise MochiSyntaxError(exp, self.filename)
pre = []
right_value_builder, right_value = self.translate(exp[2], False)
if type(right_value) is ast.Expr:
right_value = right_value.value
assign = ast.Assign(targets=targets,
value=right_value,
lineno=right_value.lineno,
col_offset=0)
pre.extend(right_value_builder)
pre.append(assign)
_, ref = self.translate_ref(ref_symbol)
return pre, ref
#@syntax('del')
#def translate_del(self, exp):
# return (ast.Delete(targets=[ast.Name(id=exp[1].name,
# lineno=exp[1].lineno,
# col_offset=exp[1].col_offset,
# ctx=ast.Del())],
# lineno=exp[0].lineno,
# col_offset=exp[0].col_offset),), self.translate_ref(NONE_SYM)[1]
示例6: _check_keyword
# 需要導入模塊: import ast [as 別名]
# 或者: from ast import Delete [as 別名]
def _check_keyword(self, node: ast.AST) -> None:
if isinstance(node, self._forbidden_keywords):
if isinstance(node, ast.Delete):
message = 'del'
else:
message = node.__class__.__qualname__.lower()
self.add_violation(WrongKeywordViolation(node, text=message))