本文整理汇总了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