mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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:
parent
b530e174a3
commit
39ee468e09
3 changed files with 39 additions and 0 deletions
|
@ -6317,6 +6317,15 @@ class InternalsTests(BaseTestCase):
|
|||
typing._collect_parameters
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
|
||||
def test_lazy_import(self):
|
||||
import_helper.ensure_lazy_imports("typing", {
|
||||
"warnings",
|
||||
"inspect",
|
||||
"re",
|
||||
"contextlib",
|
||||
# "annotationlib", # TODO
|
||||
})
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def cached_func(x, y):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue