gh-118761: Add helper to ensure that lazy imports are actually lazy (#132614)

This ensures that if we jump through some hoops to make sure something is imported
lazily, we don't regress on importing it.

I recently already accidentally made typing import warnings and annotationlib eagerly.

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
Jelle Zijlstra 2025-04-16 20:46:36 -07:00 committed by GitHub
parent b530e174a3
commit 39ee468e09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 0 deletions

View file

@ -24,6 +24,7 @@ from typing import (
)
from test import support
from test.support import import_helper
from test.test_inspect import inspect_stock_annotations
from test.test_inspect import inspect_stringized_annotations
from test.test_inspect import inspect_stringized_annotations_2
@ -1367,3 +1368,9 @@ class ForwardRefTests(unittest.TestCase):
class TestAnnotationLib(unittest.TestCase):
def test__all__(self):
support.check__all__(self, annotationlib)
def test_lazy_imports(self):
import_helper.ensure_lazy_imports("annotationlib", {
"typing",
"warnings",
})