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


Python ast.ExtSlice方法代码示例

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


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

示例1: slicev

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

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

示例4: normalize_tuple_slice

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

示例5: visit_Slice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import ExtSlice [as 别名]
def visit_Slice (self, node):   # Only visited for dims as part of ExtSlice
        self.emit ('tuple ([')

        if node.lower == None:
            self.emit ('0')
        else:
            self.visit (node.lower)

        self.emit (', ')

        if node.upper == None:
            self.emit ('null')
        else:
            self.visit (node.upper)

        self.emit (', ')

        if node.step == None:
            self.emit ('1')
        else:
            self.visit (node.step)

        self.emit ('])') 
开发者ID:QQuick,项目名称:Transcrypt,代码行数:25,代码来源:compiler.py

示例6: slicev

# 需要导入模块: import ast [as 别名]
# 或者: from ast import ExtSlice [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) 
开发者ID:python-security,项目名称:pyt,代码行数:16,代码来源:vars_visitor.py

示例7: visit_ExtSlice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import ExtSlice [as 别名]
def visit_ExtSlice(self, node: ast.ExtSlice) -> Tuple[Any, ...]:
        """Visit each dimension of the advanced slicing and assemble the dimensions in a tuple."""
        result = tuple(self.visit(node=dim) for dim in node.dims)

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

示例8: process_ExtSlice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import ExtSlice [as 别名]
def process_ExtSlice(self, block: "Block", node: ast.ExtSlice) -> ANFNode:
        """Process extended subscript slices."""
        op = block.operation("make_tuple")
        slices = [self.process_node(block, dim) for dim in node.dims]
        return block.graph.apply(op, *slices) 
开发者ID:mila-iqia,项目名称:myia,代码行数:7,代码来源:parser.py

示例9: visit_ExtSlice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import ExtSlice [as 别名]
def visit_ExtSlice(self, node):
        has_ellipsis = any(isinstance(d, ast.Ellipsis) for d in node.dims)
        has_slice = any(isinstance(d, ast.Slice) for d in node.dims)
        new_dims = self._visit(node.dims)
        if has_ellipsis and not has_slice:
            new_dims = [nd.value if isinstance(nd, gast.Index) else nd
                        for nd in new_dims]
            new_node = gast.Index(gast.Tuple(new_dims,
                                             gast.Load()))
        else:
            new_node = gast.ExtSlice(new_dims)
        gast.copy_location(new_node, node)
        new_node.end_lineno = new_node.end_col_offset = None
        return new_node 
开发者ID:serge-sans-paille,项目名称:gast,代码行数:16,代码来源:ast2.py

示例10: make_slice_tuple

# 需要导入模块: import ast [as 别名]
# 或者: from ast import ExtSlice [as 别名]
def make_slice_tuple(toplevel, stack_builders):
    slice_ = _make_expr(toplevel, stack_builders)
    if isinstance(slice_, ast.Tuple):
        # a = b[c, d] generates Index(value=Tuple(...))
        # a = b[c:, d] generates ExtSlice(dims=[Slice(...), Index(...)])
        slice_ = normalize_tuple_slice(slice_)
    return slice_ 
开发者ID:llllllllll,项目名称:codetransformer,代码行数:9,代码来源:_343.py

示例11: p_subscriptlist_2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import ExtSlice [as 别名]
def p_subscriptlist_2(p):
    '''subscriptlist : subscript COMMA'''
    #                          1     2
    if isinstance(p[1], ast.Index):
        tup = ast.Tuple([p[1].value], ast.Load(), rule=inspect.currentframe().f_code.co_name, paren=False)
        inherit_lineno(tup, p[1].value)
        p[0] = ast.Index(tup, rule=inspect.currentframe().f_code.co_name)
        inherit_lineno(p[0], tup)
    else:
        p[0] = ast.ExtSlice([p[1]], rule=inspect.currentframe().f_code.co_name)
        inherit_lineno(p[0], p[1]) 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:13,代码来源:hgawk_grammar.py

示例12: p_subscriptlist_3

# 需要导入模块: import ast [as 别名]
# 或者: from ast import ExtSlice [as 别名]
def p_subscriptlist_3(p):
    '''subscriptlist : subscript subscriptlist_star'''
    #                          1                  2
    args = [p[1]] + p[2]
    if all(isinstance(x, ast.Index) for x in args):
        tup = ast.Tuple([x.value for x in args], ast.Load(), rule=inspect.currentframe().f_code.co_name, paren=False)
        inherit_lineno(tup, args[0].value)
        p[0] = ast.Index(tup, rule=inspect.currentframe().f_code.co_name)
        inherit_lineno(p[0], tup)
    else:
        p[0] = ast.ExtSlice(args, rule=inspect.currentframe().f_code.co_name)
        inherit_lineno(p[0], p[1]) 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:14,代码来源:hgawk_grammar.py

示例13: p_subscriptlist_4

# 需要导入模块: import ast [as 别名]
# 或者: from ast import ExtSlice [as 别名]
def p_subscriptlist_4(p):
    '''subscriptlist : subscript subscriptlist_star COMMA'''
    #                          1                  2     3
    args = [p[1]] + p[2]
    if all(isinstance(x, ast.Index) for x in args):
        tup = ast.Tuple([x.value for x in args], ast.Load(), rule=inspect.currentframe().f_code.co_name, paren=False)
        inherit_lineno(tup, args[0].value)
        p[0] = ast.Index(tup, rule=inspect.currentframe().f_code.co_name)
        inherit_lineno(p[0], tup)
    else:
        p[0] = ast.ExtSlice(args, rule=inspect.currentframe().f_code.co_name)
        inherit_lineno(p[0], p[1]) 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:14,代码来源:hgawk_grammar.py

示例14: _convert_index_like

# 需要导入模块: import ast [as 别名]
# 或者: from ast import ExtSlice [as 别名]
def _convert_index_like(self, n):
        c = self._convert
        if isinstance(n, (ast.Slice, ast.Index, ast.ExtSlice, ast.Ellipsis)):
            return c(n)  # Python < 3.8 (and also 3.8 on Windows?)
        elif isinstance(n, ast.Num):
            return Index(c(n))
        else:
            assert isinstance(n, ast.Tuple)
            dims = [self._convert_index_like(x) for x in n.elts]
            return ExtSlice(dims) 
开发者ID:flexxui,项目名称:pscript,代码行数:12,代码来源:commonast.py

示例15: _convert_ExtSlice

# 需要导入模块: import ast [as 别名]
# 或者: from ast import ExtSlice [as 别名]
def _convert_ExtSlice(self, n):
        return ExtSlice([self._convert_index_like(x) for x in n.dims])
    
    ## Expressions 
开发者ID:flexxui,项目名称:pscript,代码行数:6,代码来源:commonast.py


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