Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 52318d6

Browse files
committed
Patch #1550786: ellipsis literal.
1 parent 7cae87c commit 52318d6

19 files changed

Lines changed: 140 additions & 141 deletions

File tree

Doc/lib/libconsts.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ \section{Built-in Constants}
2626
\end{datadesc}
2727

2828
\begin{datadesc}{Ellipsis}
29-
Special value used in conjunction with extended slicing syntax.
29+
The same as \code{...}.
30+
Special value used mostly in conjunction with extended slicing syntax
31+
for user-defined container data types.
3032
% XXX Someone who understands extended slicing should fill in here.
3133
\end{datadesc}

Doc/lib/libstdtypes.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,12 +2004,12 @@ \subsection{The Null Object \label{bltin-null-object}}
20042004

20052005
\subsection{The Ellipsis Object \label{bltin-ellipsis-object}}
20062006

2007-
This object is used by extended slice notation (see the
2007+
This object is mostly used by extended slice notation (see the
20082008
\citetitle[../ref/ref.html]{Python Reference Manual}). It supports no
20092009
special operations. There is exactly one ellipsis object, named
20102010
\constant{Ellipsis} (a built-in name).
20112011

2012-
It is written as \code{Ellipsis}.
2012+
It is written as \code{Ellipsis} or \code{...}.
20132013

20142014
\subsection{Boolean Values}
20152015

Doc/ref/ref3.tex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ \section{The standard type hierarchy\label{types}}
148148

149149
\item[Ellipsis]
150150
This type has a single value. There is a single object with this value.
151-
This object is accessed through the built-in name \code{Ellipsis}.
152-
It is used to indicate the presence of the \samp{...} syntax in a
153-
slice. Its truth value is true.
151+
This object is accessed through the literal \code{...} or the
152+
built-in name \code{Ellipsis}. Its truth value is true.
154153
\obindex{Ellipsis}
155154

156155
\item[Numbers]

Doc/ref/ref5.tex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,7 @@ \subsection{Slicings\label{slicings}}
411411
contains at least one comma, the key is a tuple containing the
412412
conversion of the slice items; otherwise, the conversion of the lone
413413
slice item is the key. The conversion of a slice item that is an
414-
expression is that expression. The conversion of an ellipsis slice
415-
item is the built-in \code{Ellipsis} object. The conversion of a
414+
expression is that expression. The conversion of a
416415
proper slice is a slice object (see section \ref{types}) whose
417416
\member{start}, \member{stop} and \member{step} attributes are the
418417
values of the expressions given as lower bound, upper bound and

Grammar/Grammar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ power: atom trailer* ['**' factor]
101101
atom: ('(' [yield_expr|testlist_gexp] ')' |
102102
'[' [listmaker] ']' |
103103
'{' [dictsetmaker] '}' |
104-
NAME | NUMBER | STRING+)
104+
NAME | NUMBER | STRING+ | '.' '.' '.')
105105
listmaker: test ( list_for | (',' test)* [','] )
106106
testlist_gexp: test ( gen_for | (',' test)* [','] )
107107
lambdef: 'lambda' [varargslist] ':' test
108108
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
109109
subscriptlist: subscript (',' subscript)* [',']
110-
subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]
110+
subscript: test | [test] ':' [test] [sliceop]
111111
sliceop: ':' [test]
112112
exprlist: expr (',' expr)* [',']
113113
testlist: test (',' test)* [',']

Include/Python-ast.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ struct _stmt {
180180
enum _expr_kind {BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4,
181181
IfExp_kind=5, Dict_kind=6, Set_kind=7, ListComp_kind=8,
182182
GeneratorExp_kind=9, Yield_kind=10, Compare_kind=11,
183-
Call_kind=12, Num_kind=13, Str_kind=14, Attribute_kind=15,
184-
Subscript_kind=16, Name_kind=17, List_kind=18, Tuple_kind=19};
183+
Call_kind=12, Num_kind=13, Str_kind=14, Ellipsis_kind=15,
184+
Attribute_kind=16, Subscript_kind=17, Name_kind=18,
185+
List_kind=19, Tuple_kind=20};
185186
struct _expr {
186187
enum _expr_kind kind;
187188
union {
@@ -289,7 +290,7 @@ struct _expr {
289290
int col_offset;
290291
};
291292

292-
enum _slice_kind {Ellipsis_kind=1, Slice_kind=2, ExtSlice_kind=3, Index_kind=4};
293+
enum _slice_kind {Slice_kind=1, ExtSlice_kind=2, Index_kind=3};
293294
struct _slice {
294295
enum _slice_kind kind;
295296
union {
@@ -408,6 +409,7 @@ expr_ty Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty
408409
*arena);
409410
expr_ty Num(object n, int lineno, int col_offset, PyArena *arena);
410411
expr_ty Str(string s, int lineno, int col_offset, PyArena *arena);
412+
expr_ty Ellipsis(int lineno, int col_offset, PyArena *arena);
411413
expr_ty Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
412414
lineno, int col_offset, PyArena *arena);
413415
expr_ty Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int
@@ -418,7 +420,6 @@ expr_ty List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset,
418420
PyArena *arena);
419421
expr_ty Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset,
420422
PyArena *arena);
421-
slice_ty Ellipsis(PyArena *arena);
422423
slice_ty Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena);
423424
slice_ty ExtSlice(asdl_seq * dims, PyArena *arena);
424425
slice_ty Index(expr_ty value, PyArena *arena);

Lib/compiler/ast.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -427,19 +427,6 @@ def getChildNodes(self):
427427
def __repr__(self):
428428
return "Div((%s, %s))" % (repr(self.left), repr(self.right))
429429

430-
class Ellipsis(Node):
431-
def __init__(self, lineno=None):
432-
self.lineno = lineno
433-
434-
def getChildren(self):
435-
return ()
436-
437-
def getChildNodes(self):
438-
return ()
439-
440-
def __repr__(self):
441-
return "Ellipsis()"
442-
443430
class FloorDiv(Node):
444431
def __init__(self, (left, right), lineno=None):
445432
self.left = left

Lib/compiler/pycodegen.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,9 +1214,6 @@ def visitBitxor(self, node):
12141214

12151215
# object constructors
12161216

1217-
def visitEllipsis(self, node):
1218-
self.emit('LOAD_CONST', Ellipsis)
1219-
12201217
def visitTuple(self, node):
12211218
self.set_lineno(node)
12221219
for elt in node.nodes:

Lib/compiler/transformer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def __init__(self):
113113
token.LBRACE: self.atom_lbrace,
114114
token.NUMBER: self.atom_number,
115115
token.STRING: self.atom_string,
116+
token.DOT: self.atom_ellipsis,
116117
token.NAME: self.atom_name,
117118
}
118119
self.encoding = None
@@ -747,6 +748,9 @@ def atom_string(self, nodelist):
747748
k += self.decode_literal(node[1])
748749
return Const(k, lineno=nodelist[0][2])
749750

751+
def atom_ellipsis(self, nodelist):
752+
return Const(Ellipsis, lineno=nodelist[0][2])
753+
750754
def atom_name(self, nodelist):
751755
return Name(nodelist[0][1], lineno=nodelist[0][2])
752756

@@ -1276,11 +1280,9 @@ def com_subscriptlist(self, primary, nodelist, assigning):
12761280
lineno=extractLineNo(nodelist))
12771281

12781282
def com_subscript(self, node):
1279-
# slice_item: expression | proper_slice | ellipsis
1283+
# slice_item: expression | proper_slice
12801284
ch = node[1]
12811285
t = ch[0]
1282-
if t == token.DOT and node[2][0] == token.DOT:
1283-
return Ellipsis()
12841286
if t == token.COLON or len(node) > 2:
12851287
return self.com_sliceobj(node)
12861288
return self.com_node(ch)

Lib/test/output/test_grammar

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test_grammar
77
1.1.2.2 Long integers
88
1.1.2.3 Floating point
99
1.1.3 String literals
10+
1.1.4 Ellipsis literal
1011
1.2 Grammar
1112
single_input
1213
file_input

0 commit comments

Comments
 (0)