comparison Python/future.c @ 75868:f57cbcefde34 3.2

check by equality for __future__ not identity (closes #14378)
author Benjamin Peterson <benjamin@python.org>
date Thu, 22 Mar 2012 08:19:04 -0400
parents 724920a015f7
children 1b467efb9b27
comparison
equal deleted inserted replaced
75859:64f1b8ad9214 75868:f57cbcefde34
58 static int 58 static int
59 future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) 59 future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename)
60 { 60 {
61 int i, found_docstring = 0, done = 0, prev_line = 0; 61 int i, found_docstring = 0, done = 0, prev_line = 0;
62 62
63 static PyObject *future;
64 if (!future) {
65 future = PyUnicode_InternFromString("__future__");
66 if (!future)
67 return 0;
68 }
69
70 if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) 63 if (!(mod->kind == Module_kind || mod->kind == Interactive_kind))
71 return 1; 64 return 1;
72 65
73 /* A subsequent pass will detect future imports that don't 66 /* A subsequent pass will detect future imports that don't
74 appear at the beginning of the file. There's one case, 67 appear at the beginning of the file. There's one case,
91 that can precede a future statement are another future 84 that can precede a future statement are another future
92 statement and a doc string. 85 statement and a doc string.
93 */ 86 */
94 87
95 if (s->kind == ImportFrom_kind) { 88 if (s->kind == ImportFrom_kind) {
96 if (s->v.ImportFrom.module == future) { 89 PyObject *modname = s->v.ImportFrom.module;
90 if (!PyUnicode_CompareWithASCIIString(modname, "__future__")) {
97 if (done) { 91 if (done) {
98 PyErr_SetString(PyExc_SyntaxError, 92 PyErr_SetString(PyExc_SyntaxError,
99 ERR_LATE_FUTURE); 93 ERR_LATE_FUTURE);
100 PyErr_SyntaxLocationEx(filename, s->lineno, s->col_offset); 94 PyErr_SyntaxLocationEx(filename, s->lineno, s->col_offset);
101 return 0; 95 return 0;