# 1, 2 or 3 ExprNodes, depending on how
# many slice elements were encountered.
pos = s.position()
- if s.sy == '.':
- expect_ellipsis(s)
- return [ExprNodes.EllipsisNode(pos)]
- else:
- start = p_slice_element(s, (':',))
- if s.sy != ':':
- return [start]
- s.next()
- stop = p_slice_element(s, (':', ',', ']'))
- if s.sy != ':':
- return [start, stop]
- s.next()
- step = p_slice_element(s, (':', ',', ']'))
- return [start, stop, step]
+ start = p_slice_element(s, (':',))
+ if s.sy != ':':
+ return [start]
+ s.next()
+ stop = p_slice_element(s, (':', ',', ']'))
+ if s.sy != ':':
+ return [start, stop]
+ s.next()
+ step = p_slice_element(s, (':', ',', ']'))
+ return [start, stop, step]
def p_slice_element(s, follow_set):
# Simple expression which may be missing iff
return p_dict_or_set_maker(s)
elif sy == '`':
return p_backquote_expr(s)
+ elif sy == '.':
+ expect_ellipsis(s)
+ return ExprNodes.EllipsisNode(pos)
elif sy == 'INT':
value = s.systring
s.next()
--- /dev/null
+"""
+>>> test()
+"""
+def test():
+ x = ...
+ assert x is Ellipsis
+
+ d = {}
+ d[...] = 1
+ assert d[...] == 1
+ del d[...]
+ assert ... not in d
+
+ d[..., ...] = 1
+ assert d[..., ...] == 1
+ assert d[..., Ellipsis] == 1
+ assert (Ellipsis, Ellipsis) in d
+ del d[..., ...]
+ assert (Ellipsis, Ellipsis) not in d
+