diff --git a/lazy_loader/__init__.py b/lazy_loader/__init__.py index 9774159..f356d21 100644 --- a/lazy_loader/__init__.py +++ b/lazy_loader/__init__.py @@ -118,7 +118,7 @@ def __getattr__(self, x): ) -def load(fullname, *, require=None, error_on_import=False): +def load(fullname, *, require=None, error_on_import=False, suppress_warning=False): """Return a lazily imported proxy for a module. We often see the following pattern:: @@ -174,6 +174,10 @@ def myfunc(): Whether to postpone raising import errors until the module is accessed. If set to `True`, import errors are raised as soon as `load` is called. + suppress_warning : bool + Whether to prevent emitting a warning when loading subpackages. + If set to `True`, no warning will occur. + Returns ------- pm : importlib.util._LazyModule @@ -189,10 +193,10 @@ def myfunc(): if have_module and require is None: return module - if "." in fullname: + if not suppress_warning and "." in fullname: msg = ( "subpackages can technically be lazily loaded, but it causes the " - "package to be eagerly loaded even if it is already lazily loaded." + "package to be eagerly loaded even if it is already lazily loaded. " "So, you probably shouldn't use subpackages with this lazy feature." ) warnings.warn(msg, RuntimeWarning)