Add __future__ import for print_function. It's a no-op in 3.0, but i… · pythoncapi/cpython@8782408 · GitHub
Skip to content

Commit 8782408

Browse files
committed
Add __future__ import for print_function. It's a no-op in 3.0, but it needs to not be a syntax error.
Closes issue 2436.
1 parent 2eb2c7c commit 8782408

5 files changed

Lines changed: 17 additions & 0 deletions

File tree

Include/code.h

Lines changed: 1 addition & 0 deletions

Include/compile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef struct {
2424
#define FUTURE_DIVISION "division"
2525
#define FUTURE_ABSOLUTE_IMPORT "absolute_import"
2626
#define FUTURE_WITH_STATEMENT "with_statement"
27+
#define FUTURE_PRINT_FUNCTION "print_function"
2728

2829
struct _mod; /* Declare the existence of this type */
2930
PyAPI_FUNC(PyCodeObject *) PyAST_Compile(struct _mod *, const char *,

Lib/__future__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"division",
5454
"absolute_import",
5555
"with_statement",
56+
"print_function",
5657
]
5758

5859
__all__ = ["all_feature_names"] + all_feature_names
@@ -66,6 +67,7 @@
6667
CO_FUTURE_DIVISION = 0x2000 # division
6768
CO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default
6869
CO_FUTURE_WITH_STATEMENT = 0x8000 # with statement
70+
CO_FUTURE_PRINT_FUNCTION = 0x10000 # print function
6971

7072
class _Feature:
7173
def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
@@ -114,3 +116,7 @@ def __repr__(self):
114116
with_statement = _Feature((2, 5, 0, "alpha", 1),
115117
(2, 6, 0, "alpha", 0),
116118
CO_FUTURE_WITH_STATEMENT)
119+
120+
print_function = _Feature((2, 6, 0, "alpha", 2),
121+
(3, 0, 0, "alpha", 0),
122+
CO_FUTURE_PRINT_FUNCTION)

Lib/test/test_print.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Test correct operation of the print function.
22
"""
33

4+
from __future__ import print_function
5+
46
import unittest
57
from test import test_support
68

@@ -98,6 +100,11 @@ def x(expected, args, sep=NotDefined, end=NotDefined):
98100
x('*\n', (ClassWith__str__('*'),))
99101
x('abc 1\n', (ClassWith__str__('abc'), 1))
100102

103+
# # 2.x unicode tests
104+
# x(u'1 2\n', ('1', u'2'))
105+
# x(u'u\1234\n', (u'u\1234',))
106+
# x(u' abc 1\n', (' ', ClassWith__str__(u'abc'), 1))
107+
101108
# errors
102109
self.assertRaises(TypeError, print, '', sep=3)
103110
self.assertRaises(TypeError, print, '', end=3)

Python/future.c

Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)