Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] Fix registry decorator return value #9587

Merged
merged 1 commit into from
Sep 21, 2021
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
3 changes: 2 additions & 1 deletion pytorch_lightning/utilities/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@


class _Registry(dict):
def __call__(self, cls: Type, key: Optional[str] = None, override: bool = False) -> None:
def __call__(self, cls: Type, key: Optional[str] = None, override: bool = False) -> Type:
"""Registers a class mapped to a name.

Args:
Expand All @@ -58,6 +58,7 @@ def __call__(self, cls: Type, key: Optional[str] = None, override: bool = False)
if key in self and not override:
raise MisconfigurationException(f"'{key}' is already present in the registry. HINT: Use `override=True`.")
self[key] = cls
return cls

def register_classes(self, module: ModuleType, base_cls: Type, override: bool = False) -> None:
"""This function is an utility to register all classes from a module."""
Expand Down
3 changes: 3 additions & 0 deletions tests/utilities/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,9 @@ def test_registries(tmpdir):
OPTIMIZER_REGISTRY.register_classes(torch.optim, torch.optim.Optimizer)
OPTIMIZER_REGISTRY.register_classes(torch.optim, torch.optim.Optimizer, override=True)

# test `_Registry.__call__` returns the class
assert isinstance(CustomCallback(), CustomCallback)


@pytest.mark.parametrize("use_class_path_callbacks", [False, True])
def test_registries_resolution(use_class_path_callbacks):
Expand Down