diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py index 225e954fc42..0e562906551 100644 --- a/Lib/test/test_module.py +++ b/Lib/test/test_module.py @@ -11,6 +11,7 @@ def test_uninitialized(self): # and __doc__ is None foo = ModuleType.__new__(ModuleType) self.assertTrue(foo.__dict__ is None) + self.assertRaises(SystemError, dir, foo) try: s = foo.__name__ self.fail("__name__ = %s" % repr(s)) diff --git a/Misc/NEWS b/Misc/NEWS index a9fe8165226..ee5e62b2636 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 3.2 Alpha 1? Core and Builtins ----------------- +- Issue #6707: dir() on an uninitialized module caused a crash. + - Issue #6540: Fixed crash for bytearray.translate() with invalid parameters. - Issue #6573: set.union() stopped processing inputs if an instance of self diff --git a/Objects/object.c b/Objects/object.c index 6845201c23f..e8ac8a2e469 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1265,9 +1265,11 @@ _specialized_dir_module(PyObject *obj) if (PyDict_Check(dict)) result = PyDict_Keys(dict); else { - PyErr_Format(PyExc_TypeError, - "%.200s.__dict__ is not a dictionary", - PyModule_GetName(obj)); + const char *name = PyModule_GetName(obj); + if (name) + PyErr_Format(PyExc_TypeError, + "%.200s.__dict__ is not a dictionary", + name); } }