Skip to content

Commit 88fc664

Browse files
committed
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print. * Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}. These were the ones that generated code with a print statement. In most remaining failing tests there's an issue with the soft space.
1 parent 08c47ba commit 88fc664

31 files changed

+159
-553
lines changed

Doc/lib/libdis.tex

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -353,27 +353,6 @@ \subsection{Python Byte Code Instructions}
353353
expression statement is terminated with \code{POP_STACK}.
354354
\end{opcodedesc}
355355

356-
\begin{opcodedesc}{PRINT_ITEM}{}
357-
Prints TOS to the file-like object bound to \code{sys.stdout}. There
358-
is one such instruction for each item in the \keyword{print} statement.
359-
\end{opcodedesc}
360-
361-
\begin{opcodedesc}{PRINT_ITEM_TO}{}
362-
Like \code{PRINT_ITEM}, but prints the item second from TOS to the
363-
file-like object at TOS. This is used by the extended print statement.
364-
\end{opcodedesc}
365-
366-
\begin{opcodedesc}{PRINT_NEWLINE}{}
367-
Prints a new line on \code{sys.stdout}. This is generated as the
368-
last operation of a \keyword{print} statement, unless the statement
369-
ends with a comma.
370-
\end{opcodedesc}
371-
372-
\begin{opcodedesc}{PRINT_NEWLINE_TO}{}
373-
Like \code{PRINT_NEWLINE}, but prints the new line on the file-like
374-
object on the TOS. This is used by the extended print statement.
375-
\end{opcodedesc}
376-
377356
\begin{opcodedesc}{BREAK_LOOP}{}
378357
Terminates a loop due to a \keyword{break} statement.
379358
\end{opcodedesc}

Doc/ref/ref6.tex

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ \chapter{Simple statements \label{simple}}
1212
\productioncont{| \token{augmented_assignment_stmt}}
1313
\productioncont{| \token{pass_stmt}}
1414
\productioncont{| \token{del_stmt}}
15-
\productioncont{| \token{print_stmt}}
1615
\productioncont{| \token{return_stmt}}
1716
\productioncont{| \token{yield_stmt}}
1817
\productioncont{| \token{raise_stmt}}
@@ -370,60 +369,6 @@ \section{The \keyword{del} statement \label{del}}
370369
\indexii{attribute}{deletion}
371370

372371

373-
\section{The \keyword{print} statement \label{print}}
374-
\stindex{print}
375-
376-
\begin{productionlist}
377-
\production{print_stmt}
378-
{"print" ( \optional{\token{expression} ("," \token{expression})* \optional{","}}}
379-
\productioncont{| ">>" \token{expression}
380-
\optional{("," \token{expression})+ \optional{","}} )}
381-
\end{productionlist}
382-
383-
\keyword{print} evaluates each expression in turn and writes the
384-
resulting object to standard output (see below). If an object is not
385-
a string, it is first converted to a string using the rules for string
386-
conversions. The (resulting or original) string is then written. A
387-
space is written before each object is (converted and) written, unless
388-
the output system believes it is positioned at the beginning of a
389-
line. This is the case (1) when no characters have yet been written
390-
to standard output, (2) when the last character written to standard
391-
output is \character{\e n}, or (3) when the last write operation on
392-
standard output was not a \keyword{print} statement. (In some cases
393-
it may be functional to write an empty string to standard output for
394-
this reason.) \note{Objects which act like file objects but which are
395-
not the built-in file objects often do not properly emulate this
396-
aspect of the file object's behavior, so it is best not to rely on
397-
this.}
398-
\index{output}
399-
\indexii{writing}{values}
400-
401-
A \character{\e n} character is written at the end, unless the
402-
\keyword{print} statement ends with a comma. This is the only action
403-
if the statement contains just the keyword \keyword{print}.
404-
\indexii{trailing}{comma}
405-
\indexii{newline}{suppression}
406-
407-
Standard output is defined as the file object named \code{stdout}
408-
in the built-in module \module{sys}. If no such object exists, or if
409-
it does not have a \method{write()} method, a \exception{RuntimeError}
410-
exception is raised.
411-
\indexii{standard}{output}
412-
\refbimodindex{sys}
413-
\withsubitem{(in module sys)}{\ttindex{stdout}}
414-
\exindex{RuntimeError}
415-
416-
\keyword{print} also has an extended\index{extended print statement}
417-
form, defined by the second portion of the syntax described above.
418-
This form is sometimes referred to as ``\keyword{print} chevron.''
419-
In this form, the first expression after the \code{>>} must
420-
evaluate to a ``file-like'' object, specifically an object that has a
421-
\method{write()} method as described above. With this extended form,
422-
the subsequent expressions are printed to this file object. If the
423-
first expression evaluates to \code{None}, then \code{sys.stdout} is
424-
used as the file for output.
425-
426-
427372
\section{The \keyword{return} statement \label{return}}
428373
\stindex{return}
429374

Include/Python-ast.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ struct _mod {
6262
};
6363

6464
enum _stmt_kind {FunctionDef_kind=1, ClassDef_kind=2, Return_kind=3,
65-
Delete_kind=4, Assign_kind=5, AugAssign_kind=6, Print_kind=7,
66-
For_kind=8, While_kind=9, If_kind=10, With_kind=11,
67-
Raise_kind=12, TryExcept_kind=13, TryFinally_kind=14,
68-
Assert_kind=15, Import_kind=16, ImportFrom_kind=17,
69-
Global_kind=18, Expr_kind=19, Pass_kind=20, Break_kind=21,
70-
Continue_kind=22};
65+
Delete_kind=4, Assign_kind=5, AugAssign_kind=6, For_kind=7,
66+
While_kind=8, If_kind=9, With_kind=10, Raise_kind=11,
67+
TryExcept_kind=12, TryFinally_kind=13, Assert_kind=14,
68+
Import_kind=15, ImportFrom_kind=16, Global_kind=17,
69+
Expr_kind=18, Pass_kind=19, Break_kind=20, Continue_kind=21};
7170
struct _stmt {
7271
enum _stmt_kind kind;
7372
union {
@@ -104,12 +103,6 @@ struct _stmt {
104103
expr_ty value;
105104
} AugAssign;
106105

107-
struct {
108-
expr_ty dest;
109-
asdl_seq *values;
110-
bool nl;
111-
} Print;
112-
113106
struct {
114107
expr_ty target;
115108
expr_ty iter;
@@ -392,9 +385,6 @@ stmt_ty _Py_Assign(asdl_seq * targets, expr_ty value, int lineno, int
392385
#define AugAssign(a0, a1, a2, a3, a4, a5) _Py_AugAssign(a0, a1, a2, a3, a4, a5)
393386
stmt_ty _Py_AugAssign(expr_ty target, operator_ty op, expr_ty value, int
394387
lineno, int col_offset, PyArena *arena);
395-
#define Print(a0, a1, a2, a3, a4, a5) _Py_Print(a0, a1, a2, a3, a4, a5)
396-
stmt_ty _Py_Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int
397-
col_offset, PyArena *arena);
398388
#define For(a0, a1, a2, a3, a4, a5, a6) _Py_For(a0, a1, a2, a3, a4, a5, a6)
399389
stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq *
400390
orelse, int lineno, int col_offset, PyArena *arena);

Include/opcode.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ extern "C" {
6161
#define GET_ITER 68
6262

6363
#define PRINT_EXPR 70
64-
#define PRINT_ITEM 71
65-
#define PRINT_NEWLINE 72
66-
#define PRINT_ITEM_TO 73
67-
#define PRINT_NEWLINE_TO 74
64+
6865
#define INPLACE_LSHIFT 75
6966
#define INPLACE_RSHIFT 76
7067
#define INPLACE_AND 77

Lib/compiler/ast.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -998,50 +998,6 @@ def getChildNodes(self):
998998
def __repr__(self):
999999
return "Power((%s, %s))" % (repr(self.left), repr(self.right))
10001000

1001-
class Print(Node):
1002-
def __init__(self, nodes, dest, lineno=None):
1003-
self.nodes = nodes
1004-
self.dest = dest
1005-
self.lineno = lineno
1006-
1007-
def getChildren(self):
1008-
children = []
1009-
children.extend(flatten(self.nodes))
1010-
children.append(self.dest)
1011-
return tuple(children)
1012-
1013-
def getChildNodes(self):
1014-
nodelist = []
1015-
nodelist.extend(flatten_nodes(self.nodes))
1016-
if self.dest is not None:
1017-
nodelist.append(self.dest)
1018-
return tuple(nodelist)
1019-
1020-
def __repr__(self):
1021-
return "Print(%s, %s)" % (repr(self.nodes), repr(self.dest))
1022-
1023-
class Printnl(Node):
1024-
def __init__(self, nodes, dest, lineno=None):
1025-
self.nodes = nodes
1026-
self.dest = dest
1027-
self.lineno = lineno
1028-
1029-
def getChildren(self):
1030-
children = []
1031-
children.extend(flatten(self.nodes))
1032-
children.append(self.dest)
1033-
return tuple(children)
1034-
1035-
def getChildNodes(self):
1036-
nodelist = []
1037-
nodelist.extend(flatten_nodes(self.nodes))
1038-
if self.dest is not None:
1039-
nodelist.append(self.dest)
1040-
return tuple(nodelist)
1041-
1042-
def __repr__(self):
1043-
return "Printnl(%s, %s)" % (repr(self.nodes), repr(self.dest))
1044-
10451001
class Raise(Node):
10461002
def __init__(self, expr1, expr2, expr3, lineno=None):
10471003
self.expr1 = expr1

Lib/compiler/pyassem.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,7 @@ def findDepth(self, insts, debug=0):
783783
'DELETE_SLICE+3': -3,
784784
'STORE_SUBSCR': -3,
785785
'DELETE_SUBSCR': -2,
786-
# PRINT_EXPR?
787-
'PRINT_ITEM': -1,
786+
'PRINT_EXPR': -1,
788787
'RETURN_VALUE': -1,
789788
'YIELD_VALUE': -1,
790789
'BUILD_CLASS': -2,

Lib/compiler/pycodegen.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,29 +1130,6 @@ def visitCallFunc(self, node):
11301130
opcode = callfunc_opcode_info[have_star, have_dstar]
11311131
self.emit(opcode, kw << 8 | pos)
11321132

1133-
def visitPrint(self, node, newline=0):
1134-
self.set_lineno(node)
1135-
if node.dest:
1136-
self.visit(node.dest)
1137-
for child in node.nodes:
1138-
if node.dest:
1139-
self.emit('DUP_TOP')
1140-
self.visit(child)
1141-
if node.dest:
1142-
self.emit('ROT_TWO')
1143-
self.emit('PRINT_ITEM_TO')
1144-
else:
1145-
self.emit('PRINT_ITEM')
1146-
if node.dest and not newline:
1147-
self.emit('POP_TOP')
1148-
1149-
def visitPrintnl(self, node):
1150-
self.visitPrint(node, newline=1)
1151-
if node.dest:
1152-
self.emit('PRINT_NEWLINE_TO')
1153-
else:
1154-
self.emit('PRINT_NEWLINE')
1155-
11561133
def visitReturn(self, node):
11571134
self.set_lineno(node)
11581135
self.visit(node.value)

Lib/compiler/transformer.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -387,26 +387,6 @@ def expr_stmt(self, nodelist):
387387
return AugAssign(lval, op[1], exprNode, lineno=op[2])
388388
raise WalkerError, "can't get here"
389389

390-
def print_stmt(self, nodelist):
391-
# print ([ test (',' test)* [','] ] | '>>' test [ (',' test)+ [','] ])
392-
items = []
393-
if len(nodelist) == 1:
394-
start = 1
395-
dest = None
396-
elif nodelist[1][0] == token.RIGHTSHIFT:
397-
assert len(nodelist) == 3 \
398-
or nodelist[3][0] == token.COMMA
399-
dest = self.com_node(nodelist[2])
400-
start = 4
401-
else:
402-
dest = None
403-
start = 1
404-
for i in range(start, len(nodelist), 2):
405-
items.append(self.com_node(nodelist[i]))
406-
if nodelist[-1][0] == token.COMMA:
407-
return Print(items, dest, lineno=nodelist[0][2])
408-
return Printnl(items, dest, lineno=nodelist[0][2])
409-
410390
def del_stmt(self, nodelist):
411391
return self.com_assign(nodelist[1], OP_DELETE)
412392

@@ -1480,7 +1460,6 @@ def get_docstring(self, node, n=None):
14801460
symbol.simple_stmt,
14811461
symbol.compound_stmt,
14821462
symbol.expr_stmt,
1483-
symbol.print_stmt,
14841463
symbol.del_stmt,
14851464
symbol.pass_stmt,
14861465
symbol.break_stmt,

Lib/opcode.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ def jabs_op(name, op):
100100
def_op('GET_ITER', 68)
101101

102102
def_op('PRINT_EXPR', 70)
103-
def_op('PRINT_ITEM', 71)
104-
def_op('PRINT_NEWLINE', 72)
105-
def_op('PRINT_ITEM_TO', 73)
106-
def_op('PRINT_NEWLINE_TO', 74)
103+
107104
def_op('INPLACE_LSHIFT', 75)
108105
def_op('INPLACE_RSHIFT', 76)
109106
def_op('INPLACE_AND', 77)

0 commit comments

Comments
 (0)