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


Python ast.Slice方法代码示例

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


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

示例1: slicev

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def slicev(self, node):
        if isinstance(node, ast.Slice):
            if node.lower:
                self.visit(node.lower)
            if node.upper:
                self.visit(node.upper)
            if node.step:
                self.visit(node.step)
        elif isinstance(node, ast.ExtSlice):
            if node.dims:
                for d in node.dims:
                    self.visit(d)
        else:
            self.visit(node.value)

    #  operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv 
开发者ID:python-security,项目名称:pyt,代码行数:18,代码来源:label_visitor.py

示例2: test_subscript

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def test_subscript(self):
        sub = ast.Subscript(ast.Name("x", ast.Store()), ast.Index(ast.Num(3)),
                            ast.Load())
        self.expr(sub, "must have Load context")
        x = ast.Name("x", ast.Load())
        sub = ast.Subscript(x, ast.Index(ast.Name("y", ast.Store())),
                            ast.Load())
        self.expr(sub, "must have Load context")
        s = ast.Name("x", ast.Store())
        for args in (s, None, None), (None, s, None), (None, None, s):
            sl = ast.Slice(*args)
            self.expr(ast.Subscript(x, sl, ast.Load()),
                      "must have Load context")
        sl = ast.ExtSlice([])
        self.expr(ast.Subscript(x, sl, ast.Load()), "empty dims on ExtSlice")
        sl = ast.ExtSlice([ast.Index(s)])
        self.expr(ast.Subscript(x, sl, ast.Load()), "must have Load context") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_ast.py

示例3: visit_Name

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def visit_Name( self, node ):
    self.generic_visit( node )
    if isinstance( node._object, slice ):
      if node._object.step:
        raise VerilogTranslationError(
          'Slices with steps ([start:stop:step]) are not translatable!\n',
          node.lineno
        )
      new_node = ast.Slice( ast.Num( node._object.start ),
                            ast.Num( node._object.stop ),
                            None )
      return ast.copy_location( new_node, node )
    return node

#-------------------------------------------------------------------------
# BitStructToSlice
#------------------------------------------------------------------------- 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:19,代码来源:visitors.py

示例4: visit_Attribute

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def visit_Attribute( self, node ):
    self.generic_visit( node )
    if isinstance( node._object, _SignalSlice ):
      if node._object.slice.step:
        raise VerilogTranslationError(
          'Slices with steps ([start:stop:step]) are not translatable!\n',
          node.lineno
        )
      new_node = ast.Subscript( node.value,
                   ast.Slice( ast.Num( node._object.slice.start ),
                              ast.Num( node._object.slice.stop ),
                              None ),
                   None,
                 )
      new_node._object = node._object
      return ast.copy_location( new_node, node )
    return node

#-------------------------------------------------------------------------
# InferTemporaryTypes
#------------------------------------------------------------------------- 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:23,代码来源:visitors.py

示例5: visit_Slice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def visit_Slice(self, node: ast.Slice) -> slice:
        """Visit ``lower``, ``upper`` and ``step`` and recompute the node as a ``slice``."""
        lower = None  # type: Optional[int]
        if node.lower is not None:
            lower = self.visit(node=node.lower)

        upper = None  # type: Optional[int]
        if node.upper is not None:
            upper = self.visit(node=node.upper)

        step = None  # type: Optional[int]
        if node.step is not None:
            step = self.visit(node=node.step)

        result = slice(lower, upper, step)

        self.recomputed_values[node] = result
        return result 
开发者ID:Parquery,项目名称:icontract,代码行数:20,代码来源:_recompute.py

示例6: process_Slice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def process_Slice(self, block: "Block", node: ast.Slice) -> ANFNode:
        """Process subscript slices."""
        op = block.operation("slice")
        if node.lower is None:
            lower = Constant(None)
        else:
            lower = self.process_node(block, node.lower)
        if node.upper is None:
            upper = Constant(None)
        else:
            upper = self.process_node(block, node.upper)
        if node.step is None:
            step = Constant(None)
        else:
            step = self.process_node(block, node.step)
        return block.apply(op, lower, upper, step) 
开发者ID:mila-iqia,项目名称:myia,代码行数:18,代码来源:parser.py

示例7: visit_Index

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def visit_Index(self, node):
        new_value = self._visit(node.value)
        if isinstance(new_value, ast.Ellipsis):
            new_node = new_value
        elif isinstance(new_value, ast.Tuple):
            if any(isinstance(elt, ast.Ellipsis) for elt in new_value.elts):
                new_elts = [elt if isinstance(elt, (ast.Ellipsis, ast.Slice))
                            else ast.Index(elt)
                            for elt in new_value.elts]
                new_node = ast.ExtSlice(new_elts)
            else:
                new_node = ast.Index(new_value)
        else:
            new_node = ast.Index(new_value)
        ast.copy_location(new_node, node)
        return new_node 
开发者ID:serge-sans-paille,项目名称:gast,代码行数:18,代码来源:ast2.py

示例8: normalize_tuple_slice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def normalize_tuple_slice(node):
    """
    Normalize an ast.Tuple node representing the internals of a slice.

    Returns the node wrapped in an ast.Index.
    Returns an ExtSlice node built from the tuple elements if there are any
    slices.
    """
    if not any(isinstance(elt, ast.Slice) for elt in node.elts):
        return ast.Index(value=node)

    return ast.ExtSlice(
        [
            # Wrap non-Slice nodes in Index nodes.
            elt if isinstance(elt, ast.Slice) else ast.Index(value=elt)
            for elt in node.elts
        ]
    ) 
开发者ID:llllllllll,项目名称:codetransformer,代码行数:20,代码来源:_343.py

示例9: _make_expr_build_slice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def _make_expr_build_slice(toplevel, stack_builders):
    # Arg is always either 2 or 3.  If it's 3, then the first expression is the
    # step value.
    if toplevel.arg == 3:
        step = make_expr(stack_builders)
    else:
        step = None

    def normalize_empty_slice(node):
        """
        Convert LOAD_CONST(None) to just None.

        This normalizes slices of the form a[b:None] to just a[b:].
        """
        if isinstance(node, ast.NameConstant) and node.value is None:
            return None
        return node

    upper = normalize_empty_slice(make_expr(stack_builders))
    lower = normalize_empty_slice(make_expr(stack_builders))

    return ast.Slice(lower=lower, upper=upper, step=step) 
开发者ID:llllllllll,项目名称:codetransformer,代码行数:24,代码来源:_343.py

示例10: delete_code

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def delete_code(self, target):
        if type(target) is ast.Attribute:
            return [T('delattr({}, {!r})').format(self.visit(target.value), target.attr)]
        elif type(target) is ast.Subscript:
            if type(target.slice) is ast.Slice and target.slice.step is None:
                return [T("(lambda o, **t: type('translator', (), {{t[m]: "
                          "staticmethod(object.__getattribute__(d[m], '__get__'"
                          ")(o, type(o))) for d in [object.__getattribute__("
                          "type(o), '__dict__')] for m in t if m in d}})())({},"
                          " __delitem__='__getitem__', __delslice__="
                          "'__getslice__', __len__='__len__')[{}]").format(
                              self.visit(target.value),
                              self.visit(target.slice))]
            else:
                return [T("{__operator}.delitem({}, {})").format(
                    self.visit(target.value),
                    self.slice_repr(target.slice))]
        elif type(target) is ast.Name:
            return [self.delete_var(target.id)]
        elif type(target) in (ast.List, ast.Tuple):
            return [c for elt in target.elts for c in self.delete_code(elt)]
        else:
            raise NotImplementedError('Case not caught: %s' % str(type(target))) 
开发者ID:csvoss,项目名称:onelinerizer,代码行数:25,代码来源:onelinerizer.py

示例11: _translate_get_slice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def _translate_get_slice(self, lineno, target, start=None, stop=None, step=None):
        pre = []
        target_pre, target_value = self.translate(target, False)
        pre.extend(target_pre)
        start_pre, start_value = self.translate(start, False) if start is not None else ((), None)
        pre.extend(start_pre)
        stop_pre, stop_value = self.translate(stop, False) if stop is not None else ((), None)
        pre.extend(stop_pre)
        step_pre, step_value = self.translate(step, False) if step is not None else ((), None)
        pre.extend(step_pre)
        return pre, ast.Subscript(value=target_value,
                                  slice=ast.Slice(lower=start_value,
                                                  upper=stop_value,
                                                  step=step_value),
                                  ctx=ast.Load(),
                                  lineno=lineno,
                                  col_offset=0) 
开发者ID:i2y,项目名称:mochi,代码行数:19,代码来源:translation.py

示例12: visit_Slice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def visit_Slice(self, sl: ast.Slice) -> VisitSliceReturnT:
        actions = []
        if sl.lower is None:
            lower_flattened = None
        else:
            lower_flattened, lower_actions = self.visit_expr(sl.lower)
            actions.extend(lower_actions)

        if sl.upper is None:
            upper_flattened = None
        else:
            upper_flattened, upper_actions = self.visit_expr(sl.upper)
            actions.extend(upper_actions)

        if sl.step is None:
            step_flattened = None
        else:
            step_flattened, step_actions = self.visit_expr(sl.step)
            actions.extend(step_actions)

        return ast.Slice(lower=lower_flattened, upper=upper_flattened, step=step_flattened), actions 
开发者ID:NetSys,项目名称:kappa,代码行数:23,代码来源:flatten.py

示例13: _Subscript

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def _Subscript(self, t):
    if isinstance(t.slice, ast.Index):
      #self.dispatch(t.value)
      #self.write("[")
      #self.dispatch(t.slice)
      #self.write("]")
      self.write('pyphp_subscript(')
      self.dispatch(t.value)
      self.write(', ')
      self.dispatch(t.slice)
      self.write(')')
    elif isinstance(t.slice, ast.Slice):
      self.write('array_slice(')
      self.dispatch(t.value)
      self.write(', ')
      self.dispatch(t.slice)
      self.write(')') 
开发者ID:linuxscout,项目名称:yaraspell,代码行数:19,代码来源:py2php.py

示例14: visit_Slice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def visit_Slice(self, node: ast.Slice) -> None:
        # actual slicing
        print(f"Slice: {node}")
        print(ast.dump(node))
        self.generic_visit(node) 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:7,代码来源:_devtools.py

示例15: visit_Subscript

# 需要导入模块: import ast [as 别名]
# 或者: from ast import Slice [as 别名]
def visit_Subscript(self, node: ast.Subscript) -> None:
        # iterable indexing, has Slice operations
        print(f"Subscript: {node}")
        print(ast.dump(node))
        self.generic_visit(node)

    # IN DEVELOPMENT
    ################################################################################################

    # FUTURE DEVELOPMENT
    ################################################################################################ 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:13,代码来源:_devtools.py


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