Commit 9974e1bc authored by Oren Milman's avatar Oren Milman Committed by Serhiy Storchaka

bpo-31315: Fix an assertion failure in imp.create_dynamic(), when spec.name is...

bpo-31315: Fix an assertion failure in imp.create_dynamic(), when spec.name is not a string. (#3257)
parent 6db70331
......@@ -313,6 +313,17 @@ class ImportTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, 'embedded null'):
imp.load_source(__name__, __file__ + "\0")
@support.cpython_only
def test_issue31315(self):
# There shouldn't be an assertion failure in imp.create_dynamic(),
# when spec.name is not a string.
create_dynamic = support.get_attribute(imp, 'create_dynamic')
class BadSpec:
name = None
origin = 'foo'
with self.assertRaises(TypeError):
create_dynamic(BadSpec())
class ReloadTests(unittest.TestCase):
......
Fix an assertion failure in imp.create_dynamic(), when spec.name is not a
string. Patch by Oren Milman.
......@@ -103,6 +103,11 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
if (name_unicode == NULL) {
return NULL;
}
if (!PyUnicode_Check(name_unicode)) {
PyErr_SetString(PyExc_TypeError,
"spec.name must be a string");
goto error;
}
name = get_encoded_name(name_unicode, &hook_prefix);
if (name == NULL) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment