raise TestFailed, 'dictsubclass.fromkeys created wrong type'
if type(dictlike().fromkeys('a')) is not dictlike:
raise TestFailed, 'dictsubclass.fromkeys created wrong type'
+from UserDict import UserDict
+class mydict(dict):
+ def __new__(cls, *args, **kwargs):
+ return UserDict(*args, **kwargs)
+try: mydict.fromkeys('a b c'.split())
+except TypeError: pass
+else: raise TestFailed, 'dict.fromkeys() failed to detect non-dict class.'
# dict.copy()
d = {1:1, 2:2, 3:3}
if d.copy() != {1:1, 2:2, 3:3}: raise TestFailed, 'dict copy'
PyObject *cls;
int status;
- if (!PyArg_ParseTuple(args, "OO|O:fromkeys", &cls, &seq, &value))
+ if (!PyArg_ParseTuple(args, "OO|O:fromkeys", &cls, &seq, &value))
return NULL;
d = PyObject_CallObject(cls, NULL);
if (d == NULL)
return NULL;
if (!PyDict_Check(d)) {
- PyErr_BadInternalCall();
Py_DECREF(d);
+ PyErr_SetString(PyExc_TypeError,
+ "class constructor must return a subclass of dict");
return NULL;
}