From 94363aeb2deb07f6a790428953afe100f2a204b6 Mon Sep 17 00:00:00 2001 From: ByteFlow Date: Tue, 5 May 2026 01:35:08 +0800 Subject: [PATCH] Add test for non-module-level eager import --- Lib/test/test_lazy_import/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/test/test_lazy_import/__init__.py b/Lib/test/test_lazy_import/__init__.py index a9a8cd143e0d75..b44e7d62bc9725 100644 --- a/Lib/test/test_lazy_import/__init__.py +++ b/Lib/test/test_lazy_import/__init__.py @@ -1948,6 +1948,13 @@ def test_normal_import_dis(self): else: self.assertFail("IMPORT_NAME not found") + def test_eager_import_dis(self): + """non module level import should show eager""" + code = compile("def f(): import foo", "exec", "exec") + f = io.StringIO() + dis.dis(code, file=f) + self.assertIn("foo + eager", f.getvalue()) + @unittest.skipIf(_testcapi is None, 'need the _testcapi module') class LazyCApiTests(unittest.TestCase):