diff options
author | Raymond Hettinger <python@rcn.com> | 2007-02-07 21:40:49 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2007-02-07 21:40:49 (GMT) |
commit | 113776c41134bd499efe2b404e25446b31b5c48d (patch) | |
tree | dfb8307321fb2f8cd09e42c5b85e3383c895b845 /Modules | |
parent | 05d59e2df7a780ad56b4e40f16c0a7584457b1cd (diff) | |
download | cpython-113776c41134bd499efe2b404e25446b31b5c48d.zip cpython-113776c41134bd499efe2b404e25446b31b5c48d.tar.gz cpython-113776c41134bd499efe2b404e25446b31b5c48d.tar.bz2 |
Check for a common user error with defaultdict().
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/collectionsmodule.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Modules/collectionsmodule.c b/Modules/collectionsmodule.c index a4cdcfa..f98bd49 100644 --- a/Modules/collectionsmodule.c +++ b/Modules/collectionsmodule.c @@ -1252,8 +1252,14 @@ defdict_init(PyObject *self, PyObject *args, PyObject *kwds) newargs = PyTuple_New(0); else { Py_ssize_t n = PyTuple_GET_SIZE(args); - if (n > 0) + if (n > 0) { newdefault = PyTuple_GET_ITEM(args, 0); + if (!PyCallable_Check(newdefault)) { + PyErr_SetString(PyExc_TypeError, + "first argument must be callable"); + return -1; + } + } newargs = PySequence_GetSlice(args, 1, n); } if (newargs == NULL) |