From a5d2667247f53efa776cbbf59549bbbedb0d0315 Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 16 Jun 2026 00:41:41 +0900 Subject: [PATCH 1/3] Fix __lazy_import__ without frame --- Python/bltinmodule.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index d5129bf6a5a6bc0..fa64255be00e75d 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -313,6 +313,12 @@ builtin___lazy_import___impl(PyObject *module, PyObject *name, PyThreadState *tstate = PyThreadState_GET(); if (globals == NULL) { globals = PyEval_GetGlobals(); + if (globals == NULL) { + PyErr_SetString(PyExc_TypeError, + "__lazy_import__() missing globals " + "when called without a frame"); + return NULL; + } } if (locals == NULL) { locals = globals; From 04a8160a09b90d9204d325a47da02ff162236e89 Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 16 Jun 2026 00:45:56 +0900 Subject: [PATCH 2/3] Blurb it --- .../2026-06-16-00-45-42.gh-issue-151510.HJ-kGn.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-00-45-42.gh-issue-151510.HJ-kGn.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-00-45-42.gh-issue-151510.HJ-kGn.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-00-45-42.gh-issue-151510.HJ-kGn.rst new file mode 100644 index 000000000000000..1b398c4d5e486d3 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-00-45-42.gh-issue-151510.HJ-kGn.rst @@ -0,0 +1,2 @@ +Fix a crash in :func:`__lazy_import__` when called without an explicit +``globals`` argument and without a current Python frame. From 6d8002f3e6e7b6389f311bd45fa61ff1d6b9e478 Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 16 Jun 2026 00:53:23 +0900 Subject: [PATCH 3/3] Fix news entry --- .../2026-06-16-00-45-42.gh-issue-151510.HJ-kGn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-00-45-42.gh-issue-151510.HJ-kGn.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-00-45-42.gh-issue-151510.HJ-kGn.rst index 1b398c4d5e486d3..cfa5ee8d3839c1b 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-00-45-42.gh-issue-151510.HJ-kGn.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-00-45-42.gh-issue-151510.HJ-kGn.rst @@ -1,2 +1,2 @@ -Fix a crash in :func:`__lazy_import__` when called without an explicit +Fix a crash in :func:`!__lazy_import__` when called without an explicit ``globals`` argument and without a current Python frame.