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


Python _ast.Del方法代码示例

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


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

示例1: visit_attribute

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Del [as 别名]
def visit_attribute(self, node, parent):
        """visit an Attribute node by returning a fresh instance of it"""
        context = _get_context(node)
        if context == astroid.Del:
            # FIXME : maybe we should reintroduce and visit_delattr ?
            # for instance, deactivating assign_ctx
            newnode = nodes.DelAttr(node.attr, node.lineno, node.col_offset,
                                    parent)
        elif context == astroid.Store:
            newnode = nodes.AssignAttr(node.attr, node.lineno, node.col_offset,
                                       parent)
            # Prohibit a local save if we are in an ExceptHandler.
            if not isinstance(parent, astroid.ExceptHandler):
                self._delayed_assattr.append(newnode)
        else:
            newnode = nodes.Attribute(node.attr, node.lineno, node.col_offset,
                                      parent)
        newnode.postinit(self.visit(node.value, newnode))
        return newnode 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:21,代码来源:rebuilder.py

示例2: visit_name

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Del [as 别名]
def visit_name(self, node, parent):
        """visit a Name node by returning a fresh instance of it"""
        context = _get_context(node)
        # True and False can be assigned to something in py2x, so we have to
        # check first the context.
        if context == astroid.Del:
            newnode = nodes.DelName(node.id, node.lineno, node.col_offset,
                                    parent)
        elif context == astroid.Store:
            newnode = nodes.AssignName(node.id, node.lineno, node.col_offset,
                                       parent)
        elif node.id in CONST_NAME_TRANSFORMS:
            newnode = nodes.Const(CONST_NAME_TRANSFORMS[node.id],
                                  getattr(node, 'lineno', None),
                                  getattr(node, 'col_offset', None), parent)
            return newnode
        else:
            newnode = nodes.Name(node.id, node.lineno, node.col_offset, parent)
        # XXX REMOVE me :
        if context in (astroid.Del, astroid.Store): # 'Aug' ??
            self._save_assignment(newnode)
        return newnode 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:24,代码来源:rebuilder.py

示例3: 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:zrzka,项目名称:blackmamba,代码行数:21,代码来源:checker.py

示例4: make_delete

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Del [as 别名]
def make_delete(i, bytecode):
    logger.debug("Delete: \n%s", show_bytecode(bytecode))
    op = bytecode[i][2]
    if op == DELETE_SUBSCR:
      i, subscr_expr = Statement.make_subscript(i, bytecode, context=_ast.Del())
      return i, _ast.Delete([subscr_expr])
    else:
      i, attr_expr = Statement.make_expr(i, bytecode, context=_ast.Del())
      return i, _ast.Delete([attr_expr])

    return i, None 
开发者ID:neuroo,项目名称:equip,代码行数:13,代码来源:stmt.py

示例5: make_store_delete_slice

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Del [as 别名]
def make_store_delete_slice(i, bytecode, context=None):
    op = bytecode[i][2]
    is_delete = op in DELETE_SLICE_OPCODES

    if context is None:
      context = _ast.Store() if not is_delete else _ast.Del()

    lhs_expr = None

    if op in (STORE_SLICE_0, DELETE_SLICE_0):
      i, lhs_expr = Statement.make_expr(i - 1, bytecode, context=context)
      lhs_expr = _ast.Subscript(lhs_expr,
                                _ast.Slice(None, None, None),
                                _ast.Store())
    elif op in (STORE_SLICE_1, STORE_SLICE_2, DELETE_SLICE_1, DELETE_SLICE_2):
      i, index_expr = Statement.make_expr(i - 1, bytecode)
      i, arr_expr = Statement.make_expr(i - 1, bytecode, context=context)

      args = [None] * 3
      index_index = 0 if op in (STORE_SLICE_1, DELETE_SLICE_1) else 1
      args[index_index] = index_expr
      lhs_expr = _ast.Subscript(arr_expr,
                                _ast.Slice(*args),
                                _ast.Store())
    else:
      i, end_index_expr = Statement.make_expr(i - 1, bytecode)
      i, start_index_expr = Statement.make_expr(i - 1, bytecode)
      i, arr_expr = Statement.make_expr(i - 1, bytecode, context=context)

      lhs_expr = _ast.Subscript(arr_expr,
                                _ast.Slice(start_index_expr, end_index_expr, None),
                                _ast.Store())

    if is_delete:
      return i, _ast.Delete([lhs_expr])
    else:
      i, rhs_expr = Statement.make_expr(i - 1, bytecode)
      return i, _ast.Assign([lhs_expr], rhs_expr) 
开发者ID:neuroo,项目名称:equip,代码行数:40,代码来源:stmt.py

示例6: 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


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