Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Prev Previous commit
Next Next commit
Raise ValueError instead of TypeError for empty names
  • Loading branch information
dr-carlos committed Dec 2, 2025
commit 81185df683fb2d7edd991b3ea38fc3eb69a533fd
3 changes: 1 addition & 2 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,10 +1262,9 @@ class Spec:
_imp.create_builtin(spec)

spec.name = ""
spec = Spec()

# gh-142029
with self.assertRaisesRegex(TypeError,'name must not be empty'):
with self.assertRaisesRegex(ValueError, 'name must not be empty'):
_imp.create_builtin(spec)

def test_filter_syntax_warnings_by_module(self):
Expand Down
2 changes: 1 addition & 1 deletion Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -4421,7 +4421,7 @@ _imp_create_builtin(PyObject *module, PyObject *spec)
}

if (PyUnicode_GetLength(name) == 0) {
PyErr_Format(PyExc_TypeError,
PyErr_Format(PyExc_ValueError,
"name must not be empty");
Py_DECREF(name);
return NULL;
Expand Down
Loading