Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions monai/utils/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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


Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down