From a89f4b41516b1379e6141eff6955b2818251ad22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BB=D0=B0=D1=85=D0=BE=D0=B2=20=D0=90=D0=BB?= =?UTF-8?q?=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9F=D0=B0=D0=B2=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Fri, 13 Sep 2024 14:47:28 +0000 Subject: [PATCH] fix linters --- .../common/registry/registrable.py | 24 ++----------------- turbo_alignment/pipelines/mixin/logging.py | 3 +-- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/turbo_alignment/common/registry/registrable.py b/turbo_alignment/common/registry/registrable.py index dab76f7..f6717da 100644 --- a/turbo_alignment/common/registry/registrable.py +++ b/turbo_alignment/common/registry/registrable.py @@ -48,7 +48,7 @@ def add_subclass_to_registry(subclass: Type[_T]) -> Type[_T]: return add_subclass_to_registry @classmethod - def by_name(cls: Type[_RegistrableT], name: str) -> Callable[..., _RegistrableT]: + def by_name(cls: Type[_RegistrableT], name): logger.debug(f'instantiating registered subclass {name} of {cls}') subclass, constructor = cls.resolve_class_name(name) if not constructor: @@ -84,15 +84,8 @@ def resolve_class_name(cls: Type[_RegistrableT], name: str) -> tuple[Type[_Regis f'but unable to find class {class_name} in {submodule}' ) - # is not a qualified class name - available = cls.list_available() - suggestion = _get_suggestion(name, available) raise ConfigurationError( - ( - f"'{name}' is not a registered name for '{cls.__name__}'" - + ('. ' if not suggestion else f", did you mean '{suggestion}'? ") - ) - + "If your registered class comes from custom code, you'll need to import " + "If your registered class comes from custom code, you'll need to import " "the corresponding modules. If you're using AllenNLP from the command-line, " "this is done by using the '--include-package' flag, or by specifying your imports " "in a '.allennlp_plugins' file. " @@ -154,16 +147,3 @@ def _to_params(self) -> dict[str, Any]: continue return parameter_dict - - -def _get_suggestion(name: str, available: list[str]) -> str | None: - for ch, repl_ch in (('_', '-'), ('-', '_')): - suggestion = name.replace(ch, repl_ch) - if suggestion in available: - return suggestion - from nltk.metrics.distance import edit_distance - - for suggestion in available: - if edit_distance(name, suggestion, transpositions=True) == 1: - return suggestion - return None diff --git a/turbo_alignment/pipelines/mixin/logging.py b/turbo_alignment/pipelines/mixin/logging.py index a95ae00..e0b29a8 100755 --- a/turbo_alignment/pipelines/mixin/logging.py +++ b/turbo_alignment/pipelines/mixin/logging.py @@ -1,9 +1,8 @@ from abc import ABC, abstractmethod -from allenai_common import Registrable - from turbo_alignment.common.logging.clearml import create_clearml_task from turbo_alignment.common.logging.weights_and_biases import create_wandb_run +from turbo_alignment.common.registry import Registrable from turbo_alignment.common.tf.callbacks.logging import ( ClearMLLoggingCallback, LoggingCallback,