Skip to content

Commit

Permalink
fix(similarity): function signature with annotated similarity (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
micpst authored Sep 10, 2024
1 parent 7b43493 commit 417f5ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/dbally/similarity/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions src/dbally/views/exposed_functions.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)


Expand Down

0 comments on commit 417f5ef

Please sign in to comment.