From 417f5ef4d2f0914aef911f654267fb8232541de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pstr=C4=85g?= Date: Tue, 10 Sep 2024 13:48:23 +0000 Subject: [PATCH] fix(similarity): function signature with annotated similarity (#94) --- src/dbally/similarity/index.py | 18 ++++++++++++++++++ src/dbally/views/exposed_functions.py | 11 ++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/dbally/similarity/index.py b/src/dbally/similarity/index.py index 31cfe8cf..a8307f0d 100644 --- a/src/dbally/similarity/index.py +++ b/src/dbally/similarity/index.py @@ -16,6 +16,15 @@ class AbstractSimilarityIndex(metaclass=abc.ABCMeta): is not a useful abstraction. """ + def __repr__(self) -> str: + """ + Returns the string representation of the AbstractSimilarityIndex. + + Returns: + str: The string representation of the AbstractSimilarityIndex. + """ + return f"{self.__class__.__name__}()" + @abc.abstractmethod async def update(self) -> None: """ @@ -51,6 +60,15 @@ def __init__(self, store: SimilarityStore, fetcher: SimilarityFetcher): self.store = store self.fetcher = fetcher + def __repr__(self) -> str: + """ + Returns the string representation of the SimilarityIndex. + + Returns: + str: The string representation of the SimilarityIndex. + """ + return f"{self.__class__.__name__}(store={self.store}, fetcher={self.fetcher})" + async def update(self) -> None: """ Updates the store with the latest data from the fetcher. diff --git a/src/dbally/views/exposed_functions.py b/src/dbally/views/exposed_functions.py index 55254958..efccb7ef 100644 --- a/src/dbally/views/exposed_functions.py +++ b/src/dbally/views/exposed_functions.py @@ -1,7 +1,8 @@ import re from dataclasses import dataclass -from typing import _GenericAlias # type: ignore -from typing import List, Optional, Union +from typing import List, Optional, Union, _GenericAlias # type: ignore + +from typing_extensions import _AnnotatedAlias from dbally.similarity import AbstractSimilarityIndex @@ -16,11 +17,15 @@ def parse_param_type(param_type: Union[type, _GenericAlias]) -> str: Returns: str: string representation of the type """ - if param_type in {int, float, str, bool, list, dict, set, tuple}: + if hasattr(param_type, "__name__"): return param_type.__name__ + if param_type.__module__ == "typing": return re.sub(r"\btyping\.", "", str(param_type)) + if isinstance(param_type, _AnnotatedAlias): + return parse_param_type(param_type.__origin__) + return str(param_type)