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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Victor Stinner <[email protected]>
  • Loading branch information
StanFromIreland and vstinner authored Feb 21, 2026
commit ea28d2bc1a82e9b5732e00b2fa693cb3a319ed69
16 changes: 8 additions & 8 deletions Lib/test/test_import/test_lazy_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,14 @@ def test_dunder_lazy_import_used(self):
import test.test_import.data.lazy_imports.dunder_lazy_import_used
self.assertIn("test.test_import.data.lazy_imports.basic2", sys.modules)

def test_dunder_lazy_import_non_string_name(self):
"""__lazy_import__ should reject non-string name arguments."""
with self.assertRaises(TypeError):
__lazy_import__(b"")
with self.assertRaises(TypeError):
__lazy_import__(123)
with self.assertRaises(TypeError):
__lazy_import__(None)
def test_dunder_lazy_import_invalid_arguments(self):
"""__lazy_import__ should reject invalid arguments."""
for invalid_name in (b"", 123, None):
with self.assertRaises(TypeError):
__lazy_import__(invalid_name)

with self.assertRaises(ValueError):
__lazy_import__("sys", level=-1)

def test_dunder_lazy_import_builtins(self):
"""__lazy_import__ should use module's __builtins__ for __import__."""
Expand Down
4 changes: 2 additions & 2 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -4473,8 +4473,8 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
return NULL;
}
if (!PyUnicode_Check(name)) {
_PyErr_SetString(tstate, PyExc_TypeError,
"module name must be a string");
_PyErr_Format(tstate, PyExc_TypeError,
"module name must be a string, got %T", name);
return NULL;
}
if (level < 0) {
Expand Down
Loading