Skip to content

Commit 4e1a045

Browse files
authored
Merge pull request #26 from bryanforbes/improve-sql-type-api
Improve `sql.type_api` typings
2 parents ae5cb8e + 9a085be commit 4e1a045

File tree

1 file changed

+65
-43
lines changed

1 file changed

+65
-43
lines changed

sqlalchemy-stubs/sql/type_api.pyi

Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,29 @@ 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
25+
from ..engine import Dialect
1826
from ..util import compat
1927

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

2836
_T = TypeVar("_T")
2937
_T_co = TypeVar("_T_co", covariant=True)
@@ -45,29 +53,37 @@ class _ResultProcessor(Protocol[_T_co]):
4553
def __call__(self, __value: Optional[Any]) -> Optional[_T_co]: ...
4654

4755
class TypeEngine(Traversible, Generic[_T]):
48-
class Comparator(operators.ColumnOperators):
56+
class Comparator(operators.ColumnOperators, Generic[_TE]):
4957
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): ...
58+
def __clause_element__(self) -> ClauseElement: ...
59+
expr: ClauseElement = ...
60+
type: _TE = ...
61+
def __init__(self, expr: ClauseElement) -> None: ...
62+
def operate(
63+
self, op: Any, *other: Any, **kwargs: Any
64+
) -> ClauseElement: ...
65+
def reverse_operate(
66+
self, op: Any, other: Any, **kwargs: Any
67+
) -> ClauseElement: ...
68+
def __reduce__(self) -> Any: ...
5769
hashable: bool = ...
58-
comparator_factory: Type[Any] = ...
70+
comparator_factory: Type[Comparator[TypeEngine[_T]]] = ...
5971
sort_key_function: Optional[compat._SortKeyFunction] = ...
6072
should_evaluate_none: bool = ...
6173
def evaluates_none(self: _TE) -> _TE: ...
6274
def copy(self: _TE, **kw: Any) -> _TE: ...
63-
def compare_against_backend(self, dialect: Any, conn_type: Any) -> Any: ...
75+
def compare_against_backend(
76+
self, dialect: Dialect, conn_type: Any
77+
) -> Any: ...
6478
def copy_value(self, value: _T) -> _T: ...
6579
def literal_processor(
66-
self, dialect: Any
80+
self, dialect: Dialect
6781
) -> Optional[_LiteralProcessor[_T]]: ...
68-
def bind_processor(self, dialect: Any) -> Optional[_BindProcessor[_T]]: ...
82+
def bind_processor(
83+
self, dialect: Dialect
84+
) -> Optional[_BindProcessor[_T]]: ...
6985
def result_processor(
70-
self, dialect: Any, coltype: Any
86+
self, dialect: Dialect, coltype: Any
7187
) -> Optional[_ResultProcessor[_T]]: ...
7288
def column_expression(self, colexpr: Any) -> Any: ...
7389
def bind_expression(self, bindvalue: Any) -> Any: ...
@@ -79,12 +95,12 @@ class TypeEngine(Traversible, Generic[_T]):
7995
self, type_: Type[TypeEngine[_U]], dialect_name: str
8096
) -> Variant[_U]: ...
8197
def as_generic(self, allow_nulltype: bool = ...) -> TypeEngine[Any]: ...
82-
def dialect_impl(self, dialect: Any) -> Type[Any]: ...
98+
def dialect_impl(self, dialect: Dialect) -> Type[Any]: ...
8399
def adapt(self, __cls: Type[_U], **kw: Any) -> _U: ...
84100
def coerce_compared_value(
85101
self, op: Any, value: Any
86102
) -> TypeEngine[Any]: ...
87-
def compile(self, dialect: Optional[Any] = ...) -> Any: ...
103+
def compile(self, dialect: Optional[Dialect] = ...) -> Any: ...
88104

89105
class VisitableCheckKWArg(util.EnsureKWArgType, TraversibleType): ...
90106

@@ -110,25 +126,31 @@ class TypeDecorator(SchemaEventTarget, TypeEngine[_T]):
110126
impl: Any = ...
111127
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
112128
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): ...
129+
class Comparator(TypeEngine.Comparator[_TE]):
130+
def operate(
131+
self, op: Any, *other: Any, **kwargs: Any
132+
) -> ClauseElement: ...
133+
def reverse_operate(
134+
self, op: Any, other: Any, **kwargs: Any
135+
) -> ClauseElement: ...
116136
@property
117-
def comparator_factory(self) -> Type[Any]: ... # type: ignore[override]
118-
def type_engine(self, dialect: Any) -> TypeEngine[Any]: ...
119-
def load_dialect_impl(self, dialect: Any) -> TypeEngine[Any]: ...
137+
def comparator_factory(self) -> Type[Comparator[TypeEngine[_T]]]: ... # type: ignore[override]
138+
def type_engine(self, dialect: Dialect) -> TypeEngine[Any]: ...
139+
def load_dialect_impl(self, dialect: Dialect) -> TypeEngine[Any]: ...
120140
def __getattr__(self, key: Any) -> Any: ...
121141
def process_literal_param(
122-
self, value: Optional[_T], dialect: Any
142+
self, value: Optional[_T], dialect: Dialect
123143
) -> str: ...
124-
def process_bind_param(self, value: Optional[_T], dialect: Any) -> Any: ...
144+
def process_bind_param(
145+
self, value: Optional[_T], dialect: Dialect
146+
) -> Any: ...
125147
def process_result_value(
126-
self, value: Any, dialect: Any
148+
self, value: Any, dialect: Dialect
127149
) -> Optional[_T]: ...
128-
def literal_processor(self, dialect: Any) -> _LiteralProcessor[_T]: ...
129-
def bind_processor(self, dialect: Any) -> _BindProcessor[_T]: ...
150+
def literal_processor(self, dialect: Dialect) -> _LiteralProcessor[_T]: ...
151+
def bind_processor(self, dialect: Dialect) -> _BindProcessor[_T]: ...
130152
def result_processor(
131-
self, dialect: Any, coltype: Any
153+
self, dialect: Dialect, coltype: Any
132154
) -> _ResultProcessor[_T]: ...
133155
def bind_expression(self, bindparam: Any) -> Any: ...
134156
def column_expression(self, column: Any) -> Any: ...
@@ -148,12 +170,12 @@ class Variant(TypeDecorator[_T]):
148170
def coerce_compared_value(
149171
self: _VT, operator: Any, value: Any
150172
) -> Union[_VT, TypeEngine[Any]]: ...
151-
def load_dialect_impl(self, dialect: Any) -> TypeEngine[Any]: ...
173+
def load_dialect_impl(self, dialect: Dialect) -> TypeEngine[Any]: ...
152174
def with_variant(
153175
self, type_: Type[TypeEngine[_U]], dialect_name: str
154176
) -> Variant[_U]: ...
155177
@property
156178
def comparator_factory(self) -> Type[Any]: ... # type: ignore[override]
157179

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

0 commit comments

Comments
 (0)