Python ast.Delete() Examples
The following are 8
code examples of ast.Delete().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ast
, or try the search function
.
Example #1
Source File: onelinerizer.py From onelinerizer with MIT License | 6 votes |
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)
Example #2
Source File: test_ast.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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")
Example #3
Source File: test_ast.py From ironpython3 with Apache License 2.0 | 5 votes |
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")
Example #4
Source File: hgawk_grammar.py From histogrammar-python with Apache License 2.0 | 5 votes |
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'
Example #5
Source File: test_ast.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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")
Example #6
Source File: definitions.py From vkbottle with MIT License | 5 votes |
def delete_statement(d: ast.Delete): return "".join(f"delete {find(target)};" for target in d.targets)
Example #7
Source File: translation.py From mochi with MIT License | 5 votes |
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]
Example #8
Source File: keywords.py From wemake-python-styleguide with MIT License | 5 votes |
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))