From cf58f2e28dc6cedaffae14814b789a2657a3a240 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 7 Nov 2026 19:23:50 +0300 Subject: [PATCH 1/2] gh-161564: Remove `test_type_annotations` from `lazy_imports_all_exclude.txt` --- Lib/test/lazy_imports_all_exclude.txt | 1 - Lib/test/test_type_annotations.py | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/test/lazy_imports_all_exclude.txt b/Lib/test/lazy_imports_all_exclude.txt index 45796d1db9f0a58..5e8b90eff9f18ea 100644 --- a/Lib/test/lazy_imports_all_exclude.txt +++ b/Lib/test/lazy_imports_all_exclude.txt @@ -35,5 +35,4 @@ test_pyrepl test_subprocess test_symtable test_tools -test_type_annotations test_unittest diff --git a/Lib/test/test_type_annotations.py b/Lib/test/test_type_annotations.py index cb164ccd147127b..4a3ab812547f737 100644 --- a/Lib/test/test_type_annotations.py +++ b/Lib/test/test_type_annotations.py @@ -4,6 +4,7 @@ import textwrap import types import unittest +import sys from test.support import run_code, check_syntax_error, import_helper, cpython_only from test.test_inspect import inspect_stringized_annotations @@ -158,7 +159,10 @@ def test_partially_executed_module(self): partialexe.a.__annotations__, {"v1": int, "v2": int}, ) - self.assertEqual(partialexe.b.annos, {"v1": int}) + if sys.get_lazy_imports() == "all": + self.assertEqual(partialexe.b.annos, {"v1": int, "v2": int}) + else: + self.assertEqual(partialexe.b.annos, {"v1": int}) @cpython_only def test_no_cell(self): From d5047d7f39893fb833d76c9a70b12e5f5c69ed49 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 7 Nov 2026 19:37:12 +0300 Subject: [PATCH 2/2] Address review --- Lib/test/test_type_annotations.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_type_annotations.py b/Lib/test/test_type_annotations.py index 4a3ab812547f737..68d59b9c753492e 100644 --- a/Lib/test/test_type_annotations.py +++ b/Lib/test/test_type_annotations.py @@ -159,10 +159,11 @@ def test_partially_executed_module(self): partialexe.a.__annotations__, {"v1": int, "v2": int}, ) + # Module execution semantics differ based on the lazy imports mode: if sys.get_lazy_imports() == "all": - self.assertEqual(partialexe.b.annos, {"v1": int, "v2": int}) + self.assertEqual(partialexe.b.annos, {"v1": int, "v2": int}) # full else: - self.assertEqual(partialexe.b.annos, {"v1": int}) + self.assertEqual(partialexe.b.annos, {"v1": int}) # partial @cpython_only def test_no_cell(self):