diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py index aa5ee498540..0fd82ea713f 100644 --- a/Lib/test/test_module.py +++ b/Lib/test/test_module.py @@ -22,7 +22,7 @@ class ModuleTests(unittest.TestCase): # and __doc__ is None foo = ModuleType.__new__(ModuleType) self.assertTrue(foo.__dict__ is None) - self.assertRaises(SystemError, dir, foo) + self.assertRaises(TypeError, dir, foo) try: s = foo.__name__ self.fail("__name__ = %s" % repr(s)) diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index cdb365d29a9..04346f7ad10 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -481,7 +481,7 @@ PyModule_GetNameObject(PyObject *m) return NULL; } d = ((PyModuleObject *)m)->md_dict; - if (d == NULL || + if (d == NULL || !PyDict_Check(d) || (name = _PyDict_GetItemIdWithError(d, &PyId___name__)) == NULL || !PyUnicode_Check(name)) { @@ -824,11 +824,7 @@ module_dir(PyObject *self, PyObject *args) } } else { - const char *name = PyModule_GetName(self); - if (name) - PyErr_Format(PyExc_TypeError, - "%.200s.__dict__ is not a dictionary", - name); + PyErr_Format(PyExc_TypeError, ".__dict__ is not a dictionary"); } }