當前位置: 首頁>>代碼示例>>Python>>正文


Python ast.Delete方法代碼示例

本文整理匯總了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) 
開發者ID:csvoss,項目名稱:onelinerizer,代碼行數:19,代碼來源:onelinerizer.py

示例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") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:test_ast.py

示例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' 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:12,代碼來源:hgawk_grammar.py

示例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) 
開發者ID:timoniq,項目名稱:vkbottle,代碼行數:4,代碼來源:definitions.py

示例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] 
開發者ID:i2y,項目名稱:mochi,代碼行數:40,代碼來源:translation.py

示例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)) 
開發者ID:wemake-services,項目名稱:wemake-python-styleguide,代碼行數:10,代碼來源:keywords.py


注:本文中的ast.Delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。