bugs.python.org

The following code causes an assertion failure:
import os
os.__name__ = None
os.does_not_exist
this is because module_getattro() (in Objects/moduleobject.c) assumes that
__name__ is a string, and passes it to PyErr_Format(), which asserts it is a
string.
if we fixed that one (so that the code above would raise an AttributeError),
the following code would still cause an assertion failure:
import os
os.__name__ = None
from os import does_not_exist
this is because import_from() (in Python/ceval.c) also assumes that __name__
is a string, and passes it to PyUnicode_FromFormat(), which asserts it is a
string.
BTW, while we are in module_getattro(): isn't the second call to PyErr_Clear()
redundant? (Ethan, IIUC, you worked on this as part of #8297 some years ago..)

Read the original on bugs.python.org ↗