from __future__ import with_statement addon for 'with', mostly written by
Neal.
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 07de6cb..c4861c3 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -371,7 +371,7 @@
}
PyTuple_SET_ITEM(fnames, i, field);
}
- result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
+ result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
type, base, "_fields", fnames, "__module__", "_ast");
Py_DECREF(fnames);
return (PyTypeObject*)result;
@@ -2956,7 +2956,7 @@
if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
return;
- if (PyModule_AddStringConstant(m, "__version__", "42635") < 0)
+ if (PyModule_AddStringConstant(m, "__version__", "42649") < 0)
return;
if(PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
if(PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
diff --git a/Python/compile.c b/Python/compile.c
index 78ae6a7..13e0f6d 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -4286,6 +4286,8 @@
flags |= CO_GENERATOR;
if (c->c_flags->cf_flags & CO_FUTURE_DIVISION)
flags |= CO_FUTURE_DIVISION;
+ if (c->c_flags->cf_flags & CO_FUTURE_WITH_STATEMENT)
+ flags |= CO_FUTURE_WITH_STATEMENT;
n = PyDict_Size(c->u->u_freevars);
if (n < 0)
return -1;
diff --git a/Python/future.c b/Python/future.c
index 0a87b10..4a48ba5 100644
--- a/Python/future.c
+++ b/Python/future.c
@@ -31,6 +31,8 @@
ff->ff_features |= CO_FUTURE_DIVISION;
} else if (strcmp(feature, FUTURE_ABSIMPORT) == 0) {
ff->ff_features |= CO_FUTURE_ABSIMPORT;
+ } else if (strcmp(feature, FUTURE_WITH_STATEMENT) == 0) {
+ ff->ff_features |= CO_FUTURE_WITH_STATEMENT;
} else if (strcmp(feature, "braces") == 0) {
PyErr_SetString(PyExc_SyntaxError,
"not a chance");
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 2a6afe2..d5c86f2 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -690,8 +690,10 @@
/* compute parser flags based on compiler flags */
#define PARSER_FLAGS(flags) \
- (((flags) && (flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \
- PyPARSE_DONT_IMPLY_DEDENT : 0)
+ ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \
+ PyPARSE_DONT_IMPLY_DEDENT : 0) \
+ | ((flags)->cf_flags & CO_FUTURE_WITH_STATEMENT ? \
+ PyPARSE_WITH_IS_KEYWORD : 0)) : 0)
int
PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)