Skip to content

Commit d523bf7

Browse files
type hint fixes
1 parent 6309070 commit d523bf7

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/dbally/context/context.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import ast
22

3-
from typing import Optional, Type, Sequence
3+
from typing import Sequence, TypeVar
44
from typing_extensions import Self
55
from pydantic import BaseModel
66

77
from dbally.context.exceptions import ContextNotAvailableError
88

99

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

1213

1314
class BaseCallerContext(BaseModel):
@@ -17,11 +18,11 @@ class BaseCallerContext(BaseModel):
1718
"""
1819

1920
@classmethod
20-
def select_context(cls, contexts: Sequence[Type[Self]]) -> Type[Self]:
21+
def select_context(cls, contexts: CustomContextsList) -> Self:
2122
if not contexts:
2223
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.")
2324

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

2728
@classmethod

src/dbally/iql/_processor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ def _parse_arg(
132132
raise ContextualisationNotAllowed("The LLM detected that the context is required to execute the query while the filter signature does not allow it at all.")
133133

134134
if not _does_arg_allow_context(arg_spec):
135-
print(arg_spec)
136135
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.")
137136

138137
return parent_func_def.context_class.select_context(self.contexts)

src/dbally/views/exposed_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from dataclasses import dataclass
33
from typing import _GenericAlias # type: ignore
4-
from typing import List, Optional, Union, Type
4+
from typing import Sequence, Optional, Union, Type
55

66
from dbally.similarity import AbstractSimilarityIndex
77
from dbally.context.context import BaseCallerContext
@@ -57,7 +57,7 @@ class ExposedFunction:
5757

5858
name: str
5959
description: str
60-
parameters: List[MethodParamWithTyping]
60+
parameters: Sequence[MethodParamWithTyping]
6161
context_class: Optional[Type[BaseCallerContext]] = None
6262

6363
def __str__(self) -> str:

0 commit comments

Comments
 (0)