Skip to content

Commit d4a5a67

Browse files
author
benjamin.peterson
committed
fix __future__ imports when multiple features are given
git-svn-id: http://svn.python.org/projects/python/trunk@67030 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 6cd4dbc commit d4a5a67

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

Lib/test/test_future.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,23 @@ def test_parserhack(self):
8989
# the parser hack disabled. If a new keyword is introduced in
9090
# 2.6, change this to refer to the new future import.
9191
try:
92-
exec "from __future__ import division, with_statement; with = 0"
92+
exec "from __future__ import print_function; print 0"
9393
except SyntaxError:
9494
pass
9595
else:
9696
self.fail("syntax error didn't occur")
9797

9898
try:
99-
exec "from __future__ import (with_statement, division); with = 0"
99+
exec "from __future__ import (print_function); print 0"
100100
except SyntaxError:
101101
pass
102102
else:
103103
self.fail("syntax error didn't occur")
104104

105+
def test_multiple_features(self):
106+
test_support.unload("test.test_future5")
107+
from test import test_future5
108+
105109

106110
def test_main():
107111
test_support.run_unittest(FutureTest)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #4209: Enabling unicode_literals and the print_function in the same
16+
__future__ import didn't work.
17+
1518
- Using ``nonlocal`` as a variable name will now raise a Py3k SyntaxWarning
1619
because it is a reserved word in 3.x.
1720

Parser/parser.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,10 @@ future_hack(parser_state *ps)
206206
char *str_ch = STR(CHILD(cch, 0));
207207
if (strcmp(str_ch, FUTURE_WITH_STATEMENT) == 0) {
208208
ps->p_flags |= CO_FUTURE_WITH_STATEMENT;
209-
break;
210209
} else if (strcmp(str_ch, FUTURE_PRINT_FUNCTION) == 0) {
211210
ps->p_flags |= CO_FUTURE_PRINT_FUNCTION;
212-
break;
213211
} else if (strcmp(str_ch, FUTURE_UNICODE_LITERALS) == 0) {
214212
ps->p_flags |= CO_FUTURE_UNICODE_LITERALS;
215-
break;
216213
}
217214
}
218215
}

0 commit comments

Comments
 (0)