Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_uninitialized(self):
# 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))
Expand Down
8 changes: 2 additions & 6 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,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))
{
Expand Down Expand Up @@ -823,11 +823,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, "<module>.__dict__ is not a dictionary");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using %R to use repr(module)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think of it. Would that produce a better result, if we had one of these broken, nameless, dict-less module objects?

}
}

Expand Down