From b631a3016cad30290673cfcd1ad8c15746bec1ab Mon Sep 17 00:00:00 2001 From: Suraj Pai Date: Tue, 17 Jan 2023 23:49:46 -0500 Subject: [PATCH 1/2] Rename `path` to `__path` in instantiate Signed-off-by: Suraj Pai --- monai/utils/module.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index e5ccdf9992..ffe696a4be 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -214,7 +214,7 @@ def load_submodules(basemod, load_all: bool = True, exclude_pattern: str = "(.*[ return submodules, err_mod -def instantiate(path: str, **kwargs): +def instantiate(__path: str, **kwargs): """ Create an object instance or partial function from a class or function represented by string. `kwargs` will be part of the input arguments to the class constructor or function. @@ -226,9 +226,9 @@ def instantiate(path: str, **kwargs): for `partial` function. """ - component = locate(path) if isinstance(path, str) else path + component = locate(__path) if isinstance(__path, str) else __path if component is None: - raise ModuleNotFoundError(f"Cannot locate class or function path: '{path}'.") + raise ModuleNotFoundError(f"Cannot locate class or function path: '{__path}'.") try: if kwargs.pop("_debug_", False) or run_debug: warnings.warn( @@ -243,9 +243,9 @@ def instantiate(path: str, **kwargs): if callable(component): # support regular function, static method and class method return partial(component, **kwargs) except Exception as e: - raise RuntimeError(f"Failed to instantiate '{path}' with kwargs: {kwargs}") from e + raise RuntimeError(f"Failed to instantiate '{__path}' with kwargs: {kwargs}") from e - warnings.warn(f"Component to instantiate must represent a valid class or function, but got {path}.") + warnings.warn(f"Component to instantiate must represent a valid class or function, but got {__path}.") return component From 521ee26dbe217f489c4a0344812d45aed8677360 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Wed, 18 Jan 2023 15:16:39 +0000 Subject: [PATCH 2/2] fixes #https://github.com/Project-MONAI/MONAI/issues/5868 Signed-off-by: Wenqi Li --- setup.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.cfg b/setup.cfg index a538fc481e..591b564cb3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -144,6 +144,7 @@ max_line_length = 120 # N812 lowercase 'torch.nn.functional' imported as non lowercase 'F' # B023 https://github.com/Project-MONAI/MONAI/issues/4627 # B028 https://github.com/Project-MONAI/MONAI/issues/5855 +# B907 https://github.com/Project-MONAI/MONAI/issues/5868 ignore = E203 E501 @@ -155,6 +156,7 @@ ignore = B023 B905 B028 + B907 per_file_ignores = __init__.py: F401, __main__.py: F401 exclude = *.pyi,.git,.eggs,monai/_version.py,versioneer.py,venv,.venv,_version.py