Skip to content

Commit

Permalink
type hint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-jakub-cierocki committed Jul 3, 2024
1 parent 6309070 commit d523bf7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/dbally/context/context.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import ast

from typing import Optional, Type, Sequence
from typing import Sequence, TypeVar
from typing_extensions import Self
from pydantic import BaseModel

from dbally.context.exceptions import ContextNotAvailableError


CustomContextsList = Sequence[Type['BaseCallerContext']] # TODO confirm the naming
CustomContext = TypeVar('CustomContext', bound='BaseCallerContext', covariant=True)
CustomContextsList = Sequence[CustomContext] # TODO confirm the naming


class BaseCallerContext(BaseModel):
Expand All @@ -17,11 +18,11 @@ class BaseCallerContext(BaseModel):
"""

@classmethod
def select_context(cls, contexts: Sequence[Type[Self]]) -> Type[Self]:
def select_context(cls, contexts: CustomContextsList) -> Self:
if not contexts:
raise ContextNotAvailableError("The LLM detected that the context is required to execute the query and the filter signature allows contextualization while the context was not provided.")

# we assume here that each element of `contexts` represents a different subclass of BaseCallerContext
# this method is called from the subclass of BaseCallerContext pointing the right type of custom context
return next(filter(lambda obj: isinstance(obj, cls), contexts))

@classmethod
Expand Down
1 change: 0 additions & 1 deletion src/dbally/iql/_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def _parse_arg(
raise ContextualisationNotAllowed("The LLM detected that the context is required to execute the query while the filter signature does not allow it at all.")

if not _does_arg_allow_context(arg_spec):
print(arg_spec)
raise ContextualisationNotAllowed(f"The LLM detected that the context is required to execute the query while the filter signature does allow it for `{arg_spec.name}` argument.")

return parent_func_def.context_class.select_context(self.contexts)
Expand Down
4 changes: 2 additions & 2 deletions src/dbally/views/exposed_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from dataclasses import dataclass
from typing import _GenericAlias # type: ignore
from typing import List, Optional, Union, Type
from typing import Sequence, Optional, Union, Type

from dbally.similarity import AbstractSimilarityIndex
from dbally.context.context import BaseCallerContext
Expand Down Expand Up @@ -57,7 +57,7 @@ class ExposedFunction:

name: str
description: str
parameters: List[MethodParamWithTyping]
parameters: Sequence[MethodParamWithTyping]
context_class: Optional[Type[BaseCallerContext]] = None

def __str__(self) -> str:
Expand Down

0 comments on commit d523bf7

Please sign in to comment.