Skip to content

Commit 8801162

Browse files
committed
Improve sql.type_api typings
1 parent 5e8dee0 commit 8801162

File tree

1 file changed

+43
-28
lines changed

1 file changed

+43
-28
lines changed

sqlalchemy-stubs/sql/type_api.pyi

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,28 @@ from typing import Union
99

1010
from typing_extensions import Protocol
1111

12-
from . import operators as operators
13-
from .base import SchemaEventTarget as SchemaEventTarget
14-
from .visitors import Traversible as Traversible
15-
from .visitors import TraversibleType as TraversibleType
16-
from .. import exc as exc
17-
from .. import util as util
12+
from . import operators
13+
from .base import SchemaEventTarget
14+
from .elements import ClauseElement
15+
from .sqltypes import Boolean
16+
from .sqltypes import Indexable
17+
from .sqltypes import Integer
18+
from .sqltypes import MatchType
19+
from .sqltypes import NullType
20+
from .sqltypes import String
21+
from .sqltypes import TableValueType
22+
from .visitors import Traversible
23+
from .visitors import TraversibleType
24+
from .. import util
1825
from ..util import compat
1926

20-
BOOLEANTYPE: Any
21-
INTEGERTYPE: Any
22-
NULLTYPE: Any
23-
STRINGTYPE: Any
24-
MATCHTYPE: Any
25-
INDEXABLE: Any
26-
TABLEVALUE: Any
27+
BOOLEANTYPE: Boolean
28+
INTEGERTYPE: Integer
29+
NULLTYPE: NullType
30+
STRINGTYPE: String
31+
MATCHTYPE: MatchType
32+
INDEXABLE = Indexable
33+
TABLEVALUE: TableValueType
2734

2835
_T = TypeVar("_T")
2936
_T_co = TypeVar("_T_co", covariant=True)
@@ -45,17 +52,21 @@ class _ResultProcessor(Protocol[_T_co]):
4552
def __call__(self, __value: Optional[Any]) -> Optional[_T_co]: ...
4653

4754
class TypeEngine(Traversible, Generic[_T]):
48-
class Comparator(operators.ColumnOperators):
55+
class Comparator(operators.ColumnOperators, Generic[_TE]):
4956
default_comparator: Any = ...
50-
def __clause_element__(self): ...
51-
expr: Any = ...
52-
type: Any = ...
53-
def __init__(self, expr: Any) -> None: ...
54-
def operate(self, op: Any, *other: Any, **kwargs: Any): ...
55-
def reverse_operate(self, op: Any, other: Any, **kwargs: Any): ...
56-
def __reduce__(self): ...
57+
def __clause_element__(self) -> ClauseElement: ...
58+
expr: ClauseElement = ...
59+
type: _TE = ...
60+
def __init__(self, expr: ClauseElement) -> None: ...
61+
def operate(
62+
self, op: Any, *other: Any, **kwargs: Any
63+
) -> ClauseElement: ...
64+
def reverse_operate(
65+
self, op: Any, other: Any, **kwargs: Any
66+
) -> ClauseElement: ...
67+
def __reduce__(self) -> Any: ...
5768
hashable: bool = ...
58-
comparator_factory: Type[Any] = ...
69+
comparator_factory: Type[Comparator[TypeEngine[_T]]] = ...
5970
sort_key_function: Optional[compat._SortKeyFunction] = ...
6071
should_evaluate_none: bool = ...
6172
def evaluates_none(self: _TE) -> _TE: ...
@@ -110,11 +121,15 @@ class TypeDecorator(SchemaEventTarget, TypeEngine[_T]):
110121
impl: Any = ...
111122
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
112123
coerce_to_is_types: Tuple[Type[Any], ...] = ...
113-
class Comparator(TypeEngine.Comparator):
114-
def operate(self, op: Any, *other: Any, **kwargs: Any): ...
115-
def reverse_operate(self, op: Any, other: Any, **kwargs: Any): ...
124+
class Comparator(TypeEngine.Comparator[_TE]):
125+
def operate(
126+
self, op: Any, *other: Any, **kwargs: Any
127+
) -> ClauseElement: ...
128+
def reverse_operate(
129+
self, op: Any, other: Any, **kwargs: Any
130+
) -> ClauseElement: ...
116131
@property
117-
def comparator_factory(self) -> Type[Any]: ... # type: ignore[override]
132+
def comparator_factory(self) -> Type[Comparator[TypeEngine[_T]]]: ... # type: ignore[override]
118133
def type_engine(self, dialect: Any) -> TypeEngine[Any]: ...
119134
def load_dialect_impl(self, dialect: Any) -> TypeEngine[Any]: ...
120135
def __getattr__(self, key: Any) -> Any: ...
@@ -155,5 +170,5 @@ class Variant(TypeDecorator[_T]):
155170
@property
156171
def comparator_factory(self) -> Type[Any]: ... # type: ignore[override]
157172

158-
def to_instance(typeobj: Any, *arg: Any, **kw: Any): ...
159-
def adapt_type(typeobj: Any, colspecs: Any): ...
173+
def to_instance(typeobj: Any, *arg: Any, **kw: Any) -> Any: ...
174+
def adapt_type(typeobj: Any, colspecs: Any) -> Any: ...

0 commit comments

Comments
 (0)