diff options
author | David Wolever <david@wolever.net> | 2008-03-19 02:35:45 (GMT) |
---|---|---|
committer | David Wolever <david@wolever.net> | 2008-03-19 02:35:45 (GMT) |
commit | 2724ab99c8c81cdb032372871d8f1eebb171ebe7 (patch) | |
tree | 536d452a552c67fc395e7049db451df5ee296eaa /Modules | |
parent | fbe7c559054e33a74a330462aa8ae0682910a414 (diff) | |
download | cpython-2724ab99c8c81cdb032372871d8f1eebb171ebe7.zip cpython-2724ab99c8c81cdb032372871d8f1eebb171ebe7.tar.gz cpython-2724ab99c8c81cdb032372871d8f1eebb171ebe7.tar.bz2 |
Added zip, map, filter to future_bultins (#2171)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/future_builtins.c | 15 | ||||
-rw-r--r-- | Modules/itertoolsmodule.c | 13 |
2 files changed, 25 insertions, 3 deletions
diff --git a/Modules/future_builtins.c b/Modules/future_builtins.c index 686925d..5baaa60 100644 --- a/Modules/future_builtins.c +++ b/Modules/future_builtins.c @@ -59,11 +59,24 @@ static PyMethodDef module_functions[] = { PyMODINIT_FUNC initfuture_builtins(void) { - PyObject *m; + PyObject *m, *itertools, *iter_func; + char *it_funcs[] = {"imap", "ifilter", "izip", NULL}; + char **cur_func; m = Py_InitModule3("future_builtins", module_functions, module_doc); if (m == NULL) return; + itertools = PyImport_ImportModuleNoBlock("itertools"); + if (itertools == NULL) + return; + + for (cur_func = it_funcs; *cur_func; ++cur_func){ + iter_func = PyObject_GetAttrString(itertools, *cur_func); + if (iter_func == NULL) + return; + PyModule_AddObject(m, *cur_func+1, iter_func); + } + Py_DECREF(itertools); /* any other initialization needed */ } diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 8c3375a..a369dc9 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -2542,7 +2542,7 @@ ifilter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ifilterobject *lz; if (Py_Py3kWarningFlag && - PyErr_Warn(PyExc_DeprecationWarning, + PyErr_Warn(PyExc_DeprecationWarning, "In 3.x, itertools.ifilter() was moved to builtin filter().") < 0) return NULL; @@ -2552,6 +2552,15 @@ ifilter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (!PyArg_UnpackTuple(args, "ifilter", 2, 2, &func, &seq)) return NULL; + if (func == Py_None) { + if (Py_Py3kWarningFlag && + PyErr_Warn(PyExc_DeprecationWarning, + "ifilter with None as a first argument " + "is not supported in 3.x. Use a list " + "comprehension instead.") < 0) + return NULL; + } + /* Get iterator. */ it = PyObject_GetIter(seq); if (it == NULL) @@ -3602,7 +3611,7 @@ inititertools(void) &izip_type, &iziplongest_type, &permutations_type, - &product_type, + &product_type, &repeat_type, &groupby_type, NULL |