@@ -118,7 +118,7 @@ def __getattr__(self, x):
118
118
)
119
119
120
120
121
- def load (fullname , * , require = None , error_on_import = False ):
121
+ def load (fullname , * , require = None , error_on_import = False , suppress_warning = False ):
122
122
"""Return a lazily imported proxy for a module.
123
123
124
124
We often see the following pattern::
@@ -174,6 +174,10 @@ def myfunc():
174
174
Whether to postpone raising import errors until the module is accessed.
175
175
If set to `True`, import errors are raised as soon as `load` is called.
176
176
177
+ suppress_warning : bool
178
+ Whether to prevent emitting a warning when loading subpackages.
179
+ If set to `True`, no warning will occur.
180
+
177
181
Returns
178
182
-------
179
183
pm : importlib.util._LazyModule
@@ -189,10 +193,10 @@ def myfunc():
189
193
if have_module and require is None :
190
194
return module
191
195
192
- if "." in fullname :
196
+ if not suppress_warning and "." in fullname :
193
197
msg = (
194
198
"subpackages can technically be lazily loaded, but it causes the "
195
- "package to be eagerly loaded even if it is already lazily loaded."
199
+ "package to be eagerly loaded even if it is already lazily loaded. "
196
200
"So, you probably shouldn't use subpackages with this lazy feature."
197
201
)
198
202
warnings .warn (msg , RuntimeWarning )
0 commit comments