mirror of
https://github.com/python/cpython.git
synced 2026-02-22 07:00:51 +00:00
gh-145076: Check globals type in __lazy_import__() (#145086)
This commit is contained in:
parent
fbd3b25e00
commit
2be2dd5fc2
2 changed files with 8 additions and 0 deletions
|
|
@ -401,6 +401,8 @@ def test_dunder_lazy_import_invalid_arguments(self):
|
|||
|
||||
with self.assertRaises(ValueError):
|
||||
__lazy_import__("sys", level=-1)
|
||||
with self.assertRaises(TypeError):
|
||||
__lazy_import__("sys", globals=1)
|
||||
|
||||
def test_dunder_lazy_import_builtins(self):
|
||||
"""__lazy_import__ should use module's __builtins__ for __import__."""
|
||||
|
|
|
|||
|
|
@ -318,6 +318,12 @@ builtin___lazy_import___impl(PyObject *module, PyObject *name,
|
|||
locals = globals;
|
||||
}
|
||||
|
||||
if (!PyDict_Check(globals)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"expect dict for globals, got %T", globals);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyDict_GetItemRef(globals, &_Py_ID(__builtins__), &builtins) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue