当前位置: 首页>>代码示例>>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;未经允许,请勿转载。