當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。