当前位置: 首页>>代码示例>>Python>>正文


Python ast.Del方法代码示例

本文整理汇总了Python中ast.Del方法的典型用法代码示例。如果您正苦于以下问题:Python ast.Del方法的具体用法?Python ast.Del怎么用?Python ast.Del使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ast的用法示例。


在下文中一共展示了ast.Del方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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,)) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:21,代码来源:checker.py

示例2: 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):
            self.handleNodeLoad(node)
            if (node.id == 'locals' and isinstance(self.scope, FunctionScope) and
                    isinstance(node._pyflakes_parent, ast.Call)):
                # we are doing locals() call in current scope
                self.scope.usesLocals = True
        elif isinstance(node.ctx, ast.Store):
            self.handleNodeStore(node)
        elif PY2 and isinstance(node.ctx, ast.Param):
            self.handleNodeStore(node)
        elif isinstance(node.ctx, ast.Del):
            self.handleNodeDelete(node)
        else:
            # Unknown context
            raise RuntimeError("Got impossible expression context: %r" % (node.ctx,)) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:22,代码来源:checker.py

示例3: 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() 
开发者ID:item4,项目名称:yui,代码行数:12,代码来源:calc.py

示例4: visit_Name

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Del [as 别名]
def visit_Name(self, node: ast.Name) -> None:
        if self._is_six(node, SIX_SIMPLE_ATTRS):
            self.six_simple[_ast_to_offset(node)] = node

        if self._scope_stack:
            if isinstance(node.ctx, ast.Load):
                self._scope_stack[-1].reads.add(node.id)
            elif isinstance(node.ctx, (ast.Store, ast.Del)):
                self._scope_stack[-1].writes.add(node.id)
            else:
                raise AssertionError(node)

        self.generic_visit(node) 
开发者ID:asottile,项目名称:pyupgrade,代码行数:15,代码来源:pyupgrade.py

示例5: is_interesting_expression

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Del [as 别名]
def is_interesting_expression(node):
    # type: (ast.AST) -> bool
    """
    If this expression has a value that may not be exactly what it looks like,
    return True. Put differently, return False if this is just a literal.
    """
    return (isinstance(node, ast.expr) and
            not (isinstance(node, (ast.Num, ast.Str, getattr(ast, 'NameConstant', ()))) or
                 isinstance(getattr(node, 'ctx', None),
                            (ast.Store, ast.Del)) or
                 (isinstance(node, ast.UnaryOp) and
                  isinstance(node.op, (ast.UAdd, ast.USub)) and
                  isinstance(node.operand, ast.Num)) or
                 (isinstance(node, (ast.List, ast.Tuple, ast.Dict)) and
                  not any(is_interesting_expression(n) for n in ast.iter_child_nodes(node))))) 
开发者ID:alexmojaki,项目名称:executing,代码行数:17,代码来源:bird.py

示例6: p_del_stmt

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Del [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

示例7: translate_assign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Del [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

示例8: visit_Attribute

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Del [as 别名]
def visit_Attribute(self, attr: ast.Attribute) -> VisitExprReturnT:
        value, value_actions = self.visit_expr(attr.value)
        attr_flattened = ast.Attribute(value=value, attr=attr.attr, ctx=attr.ctx)

        ctx = attr.ctx
        if isinstance(ctx, ast.Load):
            # Store the attribute's value into a symbol.
            result_id = self.next_symbol_id()
            assign_node = assign(result_id, attr_flattened)
            return load(result_id), value_actions + [assign_node]
        elif isinstance(ctx, (ast.Store, ast.Del)):
            # Don't evaluate the attribute.
            return attr_flattened, value_actions
        else:
            raise NodeNotSupportedError(attr, "Attribute context not supported") 
开发者ID:NetSys,项目名称:kappa,代码行数:17,代码来源:flatten.py

示例9: visit_Subscript

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Del [as 别名]
def visit_Subscript(self, subscript: ast.Subscript) -> VisitExprReturnT:
        value, value_actions = self.visit_expr(subscript.value)
        sl, slice_actions = self.visit_slice(subscript.slice)
        ctx = subscript.ctx
        subscript_flattened = ast.Subscript(value=value, slice=sl, ctx=ctx)
        actions = value_actions + slice_actions

        if isinstance(ctx, ast.Load):
            result_id = self.next_symbol_id()
            assign_node = assign(result_id, subscript_flattened)
            return load(result_id), actions + [assign_node]
        elif isinstance(ctx, (ast.Store, ast.Del)):
            return subscript_flattened, actions

        raise NodeNotSupportedError(subscript, "Subscript context not supported") 
开发者ID:NetSys,项目名称:kappa,代码行数:17,代码来源:flatten.py

示例10: check_filename

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Del [as 别名]
def check_filename(self, filename):
        print(filename)
        source = Source.for_filename(filename)
        nodes = defaultdict(list)
        for node in ast.walk(source.tree):
            if isinstance(node, (
                    ast.UnaryOp,
                    ast.BinOp,
                    ast.Subscript,
                    ast.Call,
                    ast.Compare,
                    ast.Attribute
            )):
                nodes[node] = []

        code = compile(source.tree, source.filename, 'exec')
        result = list(self.check_code(code, nodes))

        if not re.search(r'^\s*if 0(:| and )', source.text, re.MULTILINE):
            for node, values in nodes.items():
                if is_unary_not(node):
                    continue

                if isinstance(getattr(node, 'ctx', None), (ast.Store, ast.Del)):
                    assert not values
                    continue

                if isinstance(node, ast.Compare):
                    if len(node.ops) > 1:
                        assert not values
                        continue

                    if is_unary_not(node.parent) and isinstance(node.ops[0], (ast.In, ast.Is)):
                        continue

                if is_literal(node):
                    continue

                if sys.version_info >= (3, 9) and in_finally(node):
                    correct = len(values) > 1
                else:
                    correct = len(values) == 1

                if not correct:
                    print(source.text, '---', node_string(source, node), node.lineno,
                          len(values), correct, values, file=sys.stderr, sep='\n')
                    self.fail()

        return result 
开发者ID:alexmojaki,项目名称:executing,代码行数:51,代码来源:test_main.py


注:本文中的ast.Del方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。