本文整理匯總了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
示例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")
示例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
示例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
]
)
示例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 ('])')
示例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)
示例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
示例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)
示例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
示例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_
示例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])
示例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])
示例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])
示例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)
示例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