Skip to content

Commit bd14b97

Browse files
authored
Merge pull request #23 from bryanforbes/improve-sql-operators
Improve `sql.operators` typings
2 parents bf143d6 + da001b3 commit bd14b97

File tree

1 file changed

+181
-119
lines changed

1 file changed

+181
-119
lines changed

sqlalchemy-stubs/sql/operators.pyi

Lines changed: 181 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,161 @@
1-
from operator import truediv
1+
from operator import add as add
2+
from operator import and_ as and_
3+
from operator import contains as contains
4+
from operator import eq as eq
5+
from operator import ge as ge
6+
from operator import getitem as getitem
7+
from operator import gt as gt
8+
from operator import inv as inv
9+
from operator import le as le
10+
from operator import lshift as lshift
11+
from operator import lt as lt
12+
from operator import mod as mod
13+
from operator import mul as mul
14+
from operator import ne as ne
15+
from operator import neg as neg
16+
from operator import or_ as or_
17+
from operator import rshift as rshift
18+
from operator import sub as sub
19+
from operator import truediv as truediv
220
from typing import Any
21+
from typing import Callable
322
from typing import Optional
23+
from typing import Type
24+
from typing import TypeVar
25+
from typing import Union
426

5-
from .. import util as util
27+
from .elements import ClauseElement
28+
from .type_api import TypeEngine
29+
30+
_F = TypeVar("_F", bound=Callable[..., Any])
631

732
div = truediv
833

934
class Operators:
10-
def __and__(self, other: Any): ...
11-
def __or__(self, other: Any): ...
12-
def __invert__(self): ...
35+
def __and__(self, other: Any) -> ClauseElement: ...
36+
def __or__(self, other: Any) -> ClauseElement: ...
37+
def __invert__(self) -> ClauseElement: ...
1338
def op(
1439
self,
1540
opstring: Any,
1641
precedence: int = ...,
1742
is_comparison: bool = ...,
18-
return_type: Optional[Any] = ...,
19-
): ...
20-
def bool_op(self, opstring: Any, precedence: int = ...): ...
21-
def operate(self, op: Any, *other: Any, **kwargs: Any) -> None: ...
22-
def reverse_operate(self, op: Any, other: Any, **kwargs: Any) -> None: ...
43+
return_type: Optional[
44+
Union[Type[TypeEngine[Any]], TypeEngine[Any]]
45+
] = ...,
46+
) -> Callable[[Any], ClauseElement]: ...
47+
def bool_op(
48+
self, opstring: Any, precedence: int = ...
49+
) -> Callable[[Any], ClauseElement]: ...
50+
def operate(
51+
self, op: Any, *other: Any, **kwargs: Any
52+
) -> ClauseElement: ...
53+
def reverse_operate(
54+
self, op: Any, other: Any, **kwargs: Any
55+
) -> ClauseElement: ...
2356

2457
class custom_op:
2558
__name__: str = ...
2659
opstring: Any = ...
27-
precedence: Any = ...
28-
is_comparison: Any = ...
29-
natural_self_precedent: Any = ...
30-
eager_grouping: Any = ...
31-
return_type: Any = ...
60+
precedence: int = ...
61+
is_comparison: bool = ...
62+
natural_self_precedent: bool = ...
63+
eager_grouping: bool = ...
64+
return_type: Optional[Union[Type[TypeEngine[Any]], TypeEngine[Any]]] = ...
3265
def __init__(
3366
self,
3467
opstring: Any,
3568
precedence: int = ...,
3669
is_comparison: bool = ...,
37-
return_type: Optional[Any] = ...,
70+
return_type: Optional[
71+
Union[Type[TypeEngine[Any]], TypeEngine[Any]]
72+
] = ...,
3873
natural_self_precedent: bool = ...,
3974
eager_grouping: bool = ...,
4075
) -> None: ...
41-
def __eq__(self, other: Any) -> Any: ...
42-
def __hash__(self) -> Any: ...
43-
def __call__(self, left: Any, right: Any, **kw: Any): ...
76+
def __eq__(self, other: Any) -> bool: ...
77+
def __hash__(self) -> int: ...
78+
def __call__(self, left: Any, right: Any, **kw: Any) -> ClauseElement: ...
4479

4580
class ColumnOperators(Operators):
4681
timetuple: Any = ...
47-
def __lt__(self, other: Any) -> Any: ...
48-
def __le__(self, other: Any) -> Any: ...
49-
__hash__: Any = ...
50-
def __eq__(self, other: Any) -> Any: ...
51-
def __ne__(self, other: Any) -> Any: ...
52-
def is_distinct_from(self, other: Any): ...
53-
def is_not_distinct_from(self, other: Any): ...
54-
isnot_distinct_from: Any = ...
55-
def __gt__(self, other: Any) -> Any: ...
56-
def __ge__(self, other: Any) -> Any: ...
57-
def __neg__(self): ...
58-
def __contains__(self, other: Any): ...
59-
def __getitem__(self, index: Any): ...
60-
def __lshift__(self, other: Any): ...
61-
def __rshift__(self, other: Any): ...
62-
def concat(self, other: Any): ...
63-
def like(self, other: Any, escape: Optional[Any] = ...): ...
64-
def ilike(self, other: Any, escape: Optional[Any] = ...): ...
65-
def in_(self, other: Any): ...
66-
def not_in(self, other: Any): ...
67-
notin_: Any = ...
68-
def not_like(self, other: Any, escape: Optional[Any] = ...): ...
69-
notlike: Any = ...
70-
def not_ilike(self, other: Any, escape: Optional[Any] = ...): ...
71-
notilike: Any = ...
72-
def is_(self, other: Any): ...
73-
def is_not(self, other: Any): ...
82+
def __lt__(self, other: Any) -> ClauseElement: ...
83+
def __le__(self, other: Any) -> ClauseElement: ...
84+
def __eq__(self, other: Any) -> ClauseElement: ... # type: ignore[override]
85+
def __ne__(self, other: Any) -> ClauseElement: ... # type: ignore[override]
86+
def is_distinct_from(self, other: Any) -> ClauseElement: ...
87+
def is_not_distinct_from(self, other: Any) -> ClauseElement: ...
88+
def isnot_distinct_from(self, other: Any) -> ClauseElement: ...
89+
def __gt__(self, other: Any) -> ClauseElement: ...
90+
def __ge__(self, other: Any) -> ClauseElement: ...
91+
def __neg__(self) -> ClauseElement: ...
92+
def __contains__(self, other: Any) -> ClauseElement: ...
93+
def __getitem__(self, index: Any) -> ClauseElement: ...
94+
def __lshift__(self, other: Any) -> ClauseElement: ...
95+
def __rshift__(self, other: Any) -> ClauseElement: ...
96+
def concat(self, other: Any) -> ClauseElement: ...
97+
def like(
98+
self, other: Any, escape: Optional[Any] = ...
99+
) -> ClauseElement: ...
100+
def ilike(
101+
self, other: Any, escape: Optional[Any] = ...
102+
) -> ClauseElement: ...
103+
def in_(self, other: Any) -> ClauseElement: ...
104+
def not_in(self, other: Any) -> ClauseElement: ...
105+
def notin_(self, other: Any) -> ClauseElement: ...
106+
def not_like(
107+
self, other: Any, escape: Optional[Any] = ...
108+
) -> ClauseElement: ...
109+
def notlike(
110+
self, other: Any, escape: Optional[Any] = ...
111+
) -> ClauseElement: ...
112+
def not_ilike(
113+
self, other: Any, escape: Optional[Any] = ...
114+
) -> ClauseElement: ...
115+
def notilike(
116+
self, other: Any, escape: Optional[Any] = ...
117+
) -> ClauseElement: ...
118+
def is_(self, other: Any) -> ClauseElement: ...
119+
def is_not(self, other: Any) -> ClauseElement: ...
74120
isnot: Any = ...
75-
def startswith(self, other: Any, **kwargs: Any): ...
76-
def endswith(self, other: Any, **kwargs: Any): ...
77-
def contains(self, other: Any, **kwargs: Any): ...
78-
def match(self, other: Any, **kwargs: Any): ...
79-
def regexp_match(self, pattern: Any, flags: Optional[Any] = ...): ...
121+
def startswith(self, other: Any, **kwargs: Any) -> ClauseElement: ...
122+
def endswith(self, other: Any, **kwargs: Any) -> ClauseElement: ...
123+
def contains(self, other: Any, **kwargs: Any) -> ClauseElement: ...
124+
def match(self, other: Any, **kwargs: Any) -> ClauseElement: ...
125+
def regexp_match(
126+
self, pattern: Any, flags: Optional[Any] = ...
127+
) -> ClauseElement: ...
80128
def regexp_replace(
81129
self, pattern: Any, replacement: Any, flags: Optional[Any] = ...
82-
): ...
83-
def desc(self): ...
84-
def asc(self): ...
85-
def nulls_first(self): ...
86-
nullsfirst: Any = ...
87-
def nulls_last(self): ...
88-
nullslast: Any = ...
89-
def collate(self, collation: Any): ...
90-
def __radd__(self, other: Any): ...
91-
def __rsub__(self, other: Any): ...
92-
def __rmul__(self, other: Any): ...
93-
def __rdiv__(self, other: Any): ...
94-
def __rmod__(self, other: Any): ...
95-
def between(self, cleft: Any, cright: Any, symmetric: bool = ...): ...
96-
def distinct(self): ...
97-
def any_(self): ...
98-
def all_(self): ...
99-
def __add__(self, other: Any): ...
100-
def __sub__(self, other: Any): ...
101-
def __mul__(self, other: Any): ...
102-
def __div__(self, other: Any): ...
103-
def __mod__(self, other: Any): ...
104-
def __truediv__(self, other: Any): ...
105-
def __rtruediv__(self, other: Any): ...
106-
107-
def commutative_op(fn: Any): ...
108-
def comparison_op(fn: Any): ...
130+
) -> ClauseElement: ...
131+
def desc(self) -> ClauseElement: ...
132+
def asc(self) -> ClauseElement: ...
133+
def nulls_first(self) -> ClauseElement: ...
134+
def nullsfirst(self) -> ClauseElement: ...
135+
def nulls_last(self) -> ClauseElement: ...
136+
def nullslast(self) -> ClauseElement: ...
137+
def collate(self, collation: Any) -> ClauseElement: ...
138+
def __radd__(self, other: Any) -> ClauseElement: ...
139+
def __rsub__(self, other: Any) -> ClauseElement: ...
140+
def __rmul__(self, other: Any) -> ClauseElement: ...
141+
def __rdiv__(self, other: Any) -> ClauseElement: ...
142+
def __rmod__(self, other: Any) -> ClauseElement: ...
143+
def between(
144+
self, cleft: Any, cright: Any, symmetric: bool = ...
145+
) -> ClauseElement: ...
146+
def distinct(self) -> ClauseElement: ...
147+
def any_(self) -> ClauseElement: ...
148+
def all_(self) -> ClauseElement: ...
149+
def __add__(self, other: Any) -> ClauseElement: ...
150+
def __sub__(self, other: Any) -> ClauseElement: ...
151+
def __mul__(self, other: Any) -> ClauseElement: ...
152+
def __div__(self, other: Any) -> ClauseElement: ...
153+
def __mod__(self, other: Any) -> ClauseElement: ...
154+
def __truediv__(self, other: Any) -> ClauseElement: ...
155+
def __rtruediv__(self, other: Any) -> ClauseElement: ...
156+
157+
def commutative_op(fn: _F) -> _F: ...
158+
def comparison_op(fn: _F) -> _F: ...
109159
def from_() -> None: ...
110160
def function_as_comparison_op() -> None: ...
111161
def as_() -> None: ...
@@ -118,98 +168,110 @@ def is_false(a: Any) -> None: ...
118168

119169
isfalse = is_false
120170

121-
def is_distinct_from(a: Any, b: Any): ...
122-
def is_not_distinct_from(a: Any, b: Any): ...
171+
def is_distinct_from(a: Any, b: Any) -> ClauseElement: ...
172+
def is_not_distinct_from(a: Any, b: Any) -> ClauseElement: ...
123173

124174
isnot_distinct_from = is_not_distinct_from
125175

126-
def is_(a: Any, b: Any): ...
127-
def is_not(a: Any, b: Any): ...
176+
def is_(a: Any, b: Any) -> ClauseElement: ...
177+
def is_not(a: Any, b: Any) -> ClauseElement: ...
128178

129179
isnot = is_not
130180

131-
def collate(a: Any, b: Any): ...
132-
def op(a: Any, opstring: Any, b: Any): ...
133-
def like_op(a: Any, b: Any, escape: Optional[Any] = ...): ...
134-
def not_like_op(a: Any, b: Any, escape: Optional[Any] = ...): ...
181+
def collate(a: Any, b: Any) -> ClauseElement: ...
182+
def op(a: Any, opstring: str, b: Any) -> ClauseElement: ...
183+
def like_op(a: Any, b: Any, escape: Optional[Any] = ...) -> ClauseElement: ...
184+
def not_like_op(
185+
a: Any, b: Any, escape: Optional[Any] = ...
186+
) -> ClauseElement: ...
135187

136188
notlike_op = not_like_op
137189

138-
def ilike_op(a: Any, b: Any, escape: Optional[Any] = ...): ...
139-
def not_ilike_op(a: Any, b: Any, escape: Optional[Any] = ...): ...
190+
def ilike_op(a: Any, b: Any, escape: Optional[Any] = ...) -> ClauseElement: ...
191+
def not_ilike_op(
192+
a: Any, b: Any, escape: Optional[Any] = ...
193+
) -> ClauseElement: ...
140194

141195
notilike_op = not_ilike_op
142196

143-
def between_op(a: Any, b: Any, c: Any, symmetric: bool = ...): ...
144-
def not_between_op(a: Any, b: Any, c: Any, symmetric: bool = ...): ...
197+
def between_op(
198+
a: Any, b: Any, c: Any, symmetric: bool = ...
199+
) -> ClauseElement: ...
200+
def not_between_op(
201+
a: Any, b: Any, c: Any, symmetric: bool = ...
202+
) -> ClauseElement: ...
145203

146204
notbetween_op = not_between_op
147205

148-
def in_op(a: Any, b: Any): ...
149-
def not_in_op(a: Any, b: Any): ...
206+
def in_op(a: Any, b: Any) -> ClauseElement: ...
207+
def not_in_op(a: Any, b: Any) -> ClauseElement: ...
150208

151209
notin_op = not_in_op
152210

153-
def distinct_op(a: Any): ...
154-
def any_op(a: Any): ...
155-
def all_op(a: Any): ...
211+
def distinct_op(a: Any) -> ClauseElement: ...
212+
def any_op(a: Any) -> ClauseElement: ...
213+
def all_op(a: Any) -> ClauseElement: ...
156214
def startswith_op(
157215
a: Any, b: Any, escape: Optional[Any] = ..., autoescape: bool = ...
158-
): ...
216+
) -> ClauseElement: ...
159217
def not_startswith_op(
160218
a: Any, b: Any, escape: Optional[Any] = ..., autoescape: bool = ...
161-
): ...
219+
) -> ClauseElement: ...
162220

163221
notstartswith_op = not_startswith_op
164222

165223
def endswith_op(
166224
a: Any, b: Any, escape: Optional[Any] = ..., autoescape: bool = ...
167-
): ...
225+
) -> ClauseElement: ...
168226
def not_endswith_op(
169227
a: Any, b: Any, escape: Optional[Any] = ..., autoescape: bool = ...
170-
): ...
228+
) -> ClauseElement: ...
171229

172230
notendswith_op = not_endswith_op
173231

174232
def contains_op(
175233
a: Any, b: Any, escape: Optional[Any] = ..., autoescape: bool = ...
176-
): ...
234+
) -> ClauseElement: ...
177235
def not_contains_op(
178236
a: Any, b: Any, escape: Optional[Any] = ..., autoescape: bool = ...
179-
): ...
237+
) -> ClauseElement: ...
180238

181239
notcontains_op = not_contains_op
182240

183-
def match_op(a: Any, b: Any, **kw: Any): ...
184-
def regexp_match_op(a: Any, b: Any, flags: Optional[Any] = ...): ...
185-
def not_regexp_match_op(a: Any, b: Any, flags: Optional[Any] = ...): ...
241+
def match_op(a: Any, b: Any, **kw: Any) -> ClauseElement: ...
242+
def regexp_match_op(
243+
a: Any, b: Any, flags: Optional[Any] = ...
244+
) -> ClauseElement: ...
245+
def not_regexp_match_op(
246+
a: Any, b: Any, flags: Optional[Any] = ...
247+
) -> ClauseElement: ...
186248
def regexp_replace_op(
187249
a: Any, b: Any, replacement: Any, flags: Optional[Any] = ...
188-
): ...
189-
def not_match_op(a: Any, b: Any, **kw: Any): ...
250+
) -> ClauseElement: ...
251+
def not_match_op(a: Any, b: Any, **kw: Any) -> ClauseElement: ...
190252

191253
notmatch_op = not_match_op
192254

193255
def comma_op(a: Any, b: Any) -> None: ...
194256
def filter_op(a: Any, b: Any) -> None: ...
195-
def concat_op(a: Any, b: Any): ...
196-
def desc_op(a: Any): ...
197-
def asc_op(a: Any): ...
198-
def nulls_first_op(a: Any): ...
257+
def concat_op(a: Any, b: Any) -> ClauseElement: ...
258+
def desc_op(a: Any) -> ClauseElement: ...
259+
def asc_op(a: Any) -> ClauseElement: ...
260+
def nulls_first_op(a: Any) -> ClauseElement: ...
199261

200262
nullsfirst_op = nulls_first_op
201263

202-
def nulls_last_op(a: Any): ...
264+
def nulls_last_op(a: Any) -> ClauseElement: ...
203265

204266
nullslast_op = nulls_last_op
205267

206268
def json_getitem_op(a: Any, b: Any) -> None: ...
207269
def json_path_getitem_op(a: Any, b: Any) -> None: ...
208-
def is_comparison(op: Any): ...
209-
def is_commutative(op: Any): ...
210-
def is_ordering_modifier(op: Any): ...
211-
def is_natural_self_precedent(op: Any): ...
212-
def is_boolean(op: Any): ...
213-
def mirror(op: Any): ...
214-
def is_associative(op: Any): ...
215-
def is_precedent(operator: Any, against: Any): ...
270+
def is_comparison(op: Any) -> bool: ...
271+
def is_commutative(op: Any) -> bool: ...
272+
def is_ordering_modifier(op: Any) -> bool: ...
273+
def is_natural_self_precedent(op: Any) -> bool: ...
274+
def is_boolean(op: Any) -> bool: ...
275+
def mirror(op: Any) -> Any: ...
276+
def is_associative(op: Any) -> bool: ...
277+
def is_precedent(operator: Any, against: Any) -> bool: ...

0 commit comments

Comments
 (0)