Skip to content

Commit ecefe34

Browse files
brittanyreymeta-codesync[bot]
authored andcommitted
eager_importer: preserve existing lazy-imports eager table
Summary: **BUG:** the eager imports list was being clobbered by an `eager_imports.install` call from configerator **FIX:** Update `importlib.set_lazy_imports` to only pass in variables if they are set to avoid clobbering existing objects. Reviewed By: ambv, alexmalyshev Differential Revision: D107679841 fbshipit-source-id: 1d482be9ef1d8e7cf28827981b1dfb4d75845cca
1 parent 3bfcf6c commit ecefe34

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Lib/importlib/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959

6060
from ._bootstrap import __import__
6161

62+
_UNSET = object()
63+
6264

6365
def is_lazy_imports_enabled():
6466
return _imp.is_lazy_imports_enabled()
@@ -74,7 +76,7 @@ def hydrate_lazy_objects():
7476
return _imp.hydrate_lazy_objects()
7577

7678

77-
def set_lazy_imports(enable = True, /, excluding = None, eager = None):
79+
def set_lazy_imports(enable = True, /, excluding = _UNSET, eager = _UNSET):
7880
"""Programmatic API for enabling lazy imports at runtime.
7981
8082
The optional argument `excluding` can be any container of strings; all the
@@ -84,7 +86,12 @@ def set_lazy_imports(enable = True, /, excluding = None, eager = None):
8486
The optional argument `eager` can be any container of strings; all imports for
8587
which the import full name is present in the container will be imported eagerly.
8688
"""
87-
return _imp._set_lazy_imports(enable, excluding=excluding, eager=eager)
89+
kwargs = {}
90+
if excluding is not _UNSET:
91+
kwargs["excluding"] = excluding
92+
if eager is not _UNSET:
93+
kwargs["eager"] = eager
94+
return _imp._set_lazy_imports(enable, **kwargs)
8895

8996

9097
def enable_lazy_imports_in_module(enable = True):

0 commit comments

Comments
 (0)