@@ -19,15 +19,21 @@ from operator import sub as sub
19
19
from operator import truediv as truediv
20
20
from typing import Any
21
21
from typing import Callable
22
+ from typing import Generic
23
+ from typing import NoReturn
22
24
from typing import Optional
23
25
from typing import Type
24
26
from typing import TypeVar
25
27
from typing import Union
26
28
29
+ from . import sqltypes
27
30
from .elements import ClauseElement
31
+ from .elements import ColumnElement
28
32
from .type_api import TypeEngine
29
33
30
34
_F = TypeVar ("_F" , bound = Callable [..., Any ])
35
+ _T = TypeVar ("_T" )
36
+ _TE = TypeVar ("_TE" , bound = TypeEngine [Any ])
31
37
32
38
div = truediv
33
39
@@ -77,137 +83,123 @@ class custom_op:
77
83
def __hash__ (self ) -> int : ...
78
84
def __call__ (self , left : Any , right : Any , ** kw : Any ) -> ClauseElement : ...
79
85
80
- class ColumnOperators (Operators ):
86
+ class ColumnOperators (Operators , Generic [ _TE ] ):
81
87
timetuple : 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 : ...
88
+ # TODO https://github.com/sqlalchemy/sqlalchemy2-stubs/issues/114
89
+ # Can we also limit the "other" parameter? Most should be
90
+ # Same TypeEngine[_T] or _T, but in case of ORM expressions
91
+ # _T is a Mapped type, can we extract the pure python type from
92
+ # a TypeEngine bounded TypeVar?
93
+ # def __lt__(
94
+ # self, other: Union[ColumnElement[TypeEngine[_T]], _T]
95
+ # ) -> ColumnElement[sqltypes.Boolean]: ...
96
+ def __lt__ (self , other : Any ) -> ColumnElement [sqltypes .Boolean ]: ...
97
+ def __le__ (self , other : Any ) -> ColumnElement [sqltypes .Boolean ]: ...
98
+ def __eq__ (self , other : Any ) -> ColumnElement [sqltypes .Boolean ]: ... # type: ignore[override]
99
+ def __ne__ (self , other : Any ) -> ColumnElement [sqltypes .Boolean ]: ... # type: ignore[override]
100
+ def is_distinct_from (
101
+ self , other : Any
102
+ ) -> ColumnElement [sqltypes .Boolean ]: ...
103
+ def is_not_distinct_from (
104
+ self , other : Any
105
+ ) -> ColumnElement [sqltypes .Boolean ]: ...
106
+ def __gt__ (self , other : Any ) -> ColumnElement [sqltypes .Boolean ]: ...
107
+ def __ge__ (self , other : Any ) -> ColumnElement [sqltypes .Boolean ]: ...
108
+ def __neg__ (self ) -> ColumnElement [_TE ]: ...
109
+ def __contains__ (self , other : Any ) -> ColumnElement [sqltypes .Boolean ]: ...
110
+ # TODO __getitem__ is hard: Arrays return Random Types and Strings return Strings?
111
+ def __getitem__ (self , index : Any ) -> ColumnElement [Any ]: ...
112
+ def __lshift__ (self , other : Any ) -> ColumnElement [_TE ]: ...
113
+ def __rshift__ (self , other : Any ) -> ColumnElement [_TE ]: ...
114
+ def concat (self , other : Any ) -> ColumnElement [sqltypes .String ]: ...
97
115
def like (
98
- self , other : Any , escape : Optional [Any ] = ...
99
- ) -> ClauseElement : ...
116
+ self , other : Any , escape : Optional [str ] = ...
117
+ ) -> ColumnElement [ sqltypes . Boolean ] : ...
100
118
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 : ...
119
+ self , other : Any , escape : Optional [str ] = ...
120
+ ) -> ColumnElement [sqltypes .Boolean ]: ...
121
+ def in_ (self , other : Any ) -> ColumnElement [sqltypes .Boolean ]: ...
122
+ def not_in (self , other : Any ) -> ColumnElement [sqltypes .Boolean ]: ...
106
123
def not_like (
107
- self , other : Any , escape : Optional [Any ] = ...
108
- ) -> ClauseElement : ...
109
- def notlike (
110
- self , other : Any , escape : Optional [Any ] = ...
111
- ) -> ClauseElement : ...
124
+ self , other : Any , escape : Optional [str ] = ...
125
+ ) -> ColumnElement [sqltypes .Boolean ]: ...
112
126
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 : ...
120
- isnot : 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 : ...
127
+ self , other : Any , escape : Optional [str ] = ...
128
+ ) -> ColumnElement [sqltypes .Boolean ]: ...
129
+ def is_ (self , other : Any ) -> ColumnElement [sqltypes .Boolean ]: ...
130
+ def is_not (self , other : Any ) -> ColumnElement [sqltypes .Boolean ]: ...
131
+ def startswith (
132
+ self , other : Any , ** kwargs : Any
133
+ ) -> ColumnElement [sqltypes .Boolean ]: ...
134
+ def endswith (
135
+ self , other : Any , ** kwargs : Any
136
+ ) -> ColumnElement [sqltypes .Boolean ]: ...
137
+ def contains (
138
+ self , other : Any , ** kwargs : Any
139
+ ) -> ColumnElement [sqltypes .Boolean ]: ...
140
+ def match (
141
+ self , other : Any , ** kwargs : Any
142
+ ) -> ColumnElement [sqltypes .Boolean ]: ...
125
143
def regexp_match (
126
144
self , pattern : Any , flags : Optional [Any ] = ...
127
- ) -> ClauseElement : ...
145
+ ) -> ColumnElement [ sqltypes . Boolean ] : ...
128
146
def regexp_replace (
129
147
self , pattern : Any , replacement : Any , flags : Optional [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 : ...
148
+ ) -> ColumnElement [sqltypes .String ]: ...
149
+ def desc (self ) -> ColumnElement [sqltypes .NullType ]: ...
150
+ def asc (self ) -> ColumnElement [sqltypes .NullType ]: ...
151
+ def nulls_first (self ) -> ColumnElement [sqltypes .NullType ]: ...
152
+ def nulls_last (self ) -> ColumnElement [sqltypes .NullType ]: ...
153
+ def collate (self , collation : str ) -> ColumnElement [_TE ]: ...
154
+ def __radd__ (self , other : Any ) -> ColumnElement [_TE ]: ...
155
+ def __rsub__ (self , other : Any ) -> ColumnElement [_TE ]: ...
156
+ def __rmul__ (self , other : Any ) -> ColumnElement [_TE ]: ...
157
+ def __rdiv__ (self , other : Any ) -> ColumnElement [_TE ]: ...
158
+ def __rmod__ (self , other : Any ) -> ColumnElement [_TE ]: ...
143
159
def between (
144
160
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 : ...
161
+ ) -> ColumnElement [ sqltypes . Boolean ] : ...
162
+ def distinct (self ) -> ColumnElement [ _TE ] : ...
163
+ def any_ (self ) -> ColumnElement [ sqltypes . NullType ] : ...
164
+ def all_ (self ) -> ColumnElement [ sqltypes . NullType ] : ...
165
+ def __add__ (self , other : Any ) -> ColumnElement [ _TE ] : ...
166
+ def __sub__ (self , other : Any ) -> ColumnElement [ _TE ] : ...
167
+ def __mul__ (self , other : Any ) -> ColumnElement [ _TE ] : ...
168
+ def __div__ (self , other : Any ) -> ColumnElement [ _TE ] : ...
169
+ def __mod__ (self , other : Any ) -> ColumnElement [ _TE ] : ...
170
+ def __truediv__ (self , other : Any ) -> ColumnElement [ _TE ] : ...
171
+ def __rtruediv__ (self , other : Any ) -> ColumnElement [ _TE ] : ...
156
172
157
173
def commutative_op (fn : _F ) -> _F : ...
158
174
def comparison_op (fn : _F ) -> _F : ...
159
- def from_ () -> None : ...
160
- def function_as_comparison_op () -> None : ...
161
- def as_ () -> None : ...
162
- def exists () -> None : ...
163
- def is_true (a : Any ) -> None : ...
164
-
165
- istrue = is_true
166
-
167
- def is_false (a : Any ) -> None : ...
168
-
169
- isfalse = is_false
170
-
175
+ def from_ () -> NoReturn : ...
176
+ def function_as_comparison_op () -> NoReturn : ...
177
+ def as_ () -> NoReturn : ...
178
+ def exists () -> NoReturn : ...
179
+ def is_true (a : Any ) -> NoReturn : ...
180
+ def is_false (a : Any ) -> NoReturn : ...
171
181
def is_distinct_from (a : Any , b : Any ) -> ClauseElement : ...
172
182
def is_not_distinct_from (a : Any , b : Any ) -> ClauseElement : ...
173
-
174
- isnot_distinct_from = is_not_distinct_from
175
-
176
183
def is_ (a : Any , b : Any ) -> ClauseElement : ...
177
184
def is_not (a : Any , b : Any ) -> ClauseElement : ...
178
-
179
- isnot = is_not
180
-
181
185
def collate (a : Any , b : Any ) -> ClauseElement : ...
182
186
def op (a : Any , opstring : str , b : Any ) -> ClauseElement : ...
183
187
def like_op (a : Any , b : Any , escape : Optional [Any ] = ...) -> ClauseElement : ...
184
188
def not_like_op (
185
189
a : Any , b : Any , escape : Optional [Any ] = ...
186
190
) -> ClauseElement : ...
187
-
188
- notlike_op = not_like_op
189
-
190
191
def ilike_op (a : Any , b : Any , escape : Optional [Any ] = ...) -> ClauseElement : ...
191
192
def not_ilike_op (
192
193
a : Any , b : Any , escape : Optional [Any ] = ...
193
194
) -> ClauseElement : ...
194
-
195
- notilike_op = not_ilike_op
196
-
197
195
def between_op (
198
196
a : Any , b : Any , c : Any , symmetric : bool = ...
199
197
) -> ClauseElement : ...
200
198
def not_between_op (
201
199
a : Any , b : Any , c : Any , symmetric : bool = ...
202
200
) -> ClauseElement : ...
203
-
204
- notbetween_op = not_between_op
205
-
206
201
def in_op (a : Any , b : Any ) -> ClauseElement : ...
207
202
def not_in_op (a : Any , b : Any ) -> ClauseElement : ...
208
-
209
- notin_op = not_in_op
210
-
211
203
def distinct_op (a : Any ) -> ClauseElement : ...
212
204
def any_op (a : Any ) -> ClauseElement : ...
213
205
def all_op (a : Any ) -> ClauseElement : ...
@@ -217,27 +209,18 @@ def startswith_op(
217
209
def not_startswith_op (
218
210
a : Any , b : Any , escape : Optional [Any ] = ..., autoescape : bool = ...
219
211
) -> ClauseElement : ...
220
-
221
- notstartswith_op = not_startswith_op
222
-
223
212
def endswith_op (
224
213
a : Any , b : Any , escape : Optional [Any ] = ..., autoescape : bool = ...
225
214
) -> ClauseElement : ...
226
215
def not_endswith_op (
227
216
a : Any , b : Any , escape : Optional [Any ] = ..., autoescape : bool = ...
228
217
) -> ClauseElement : ...
229
-
230
- notendswith_op = not_endswith_op
231
-
232
218
def contains_op (
233
219
a : Any , b : Any , escape : Optional [Any ] = ..., autoescape : bool = ...
234
220
) -> ClauseElement : ...
235
221
def not_contains_op (
236
222
a : Any , b : Any , escape : Optional [Any ] = ..., autoescape : bool = ...
237
223
) -> ClauseElement : ...
238
-
239
- notcontains_op = not_contains_op
240
-
241
224
def match_op (a : Any , b : Any , ** kw : Any ) -> ClauseElement : ...
242
225
def regexp_match_op (
243
226
a : Any , b : Any , flags : Optional [Any ] = ...
@@ -249,24 +232,15 @@ def regexp_replace_op(
249
232
a : Any , b : Any , replacement : Any , flags : Optional [Any ] = ...
250
233
) -> ClauseElement : ...
251
234
def not_match_op (a : Any , b : Any , ** kw : Any ) -> ClauseElement : ...
252
-
253
- notmatch_op = not_match_op
254
-
255
- def comma_op (a : Any , b : Any ) -> None : ...
256
- def filter_op (a : Any , b : Any ) -> None : ...
235
+ def comma_op (a : Any , b : Any ) -> NoReturn : ...
236
+ def filter_op (a : Any , b : Any ) -> NoReturn : ...
257
237
def concat_op (a : Any , b : Any ) -> ClauseElement : ...
258
238
def desc_op (a : Any ) -> ClauseElement : ...
259
239
def asc_op (a : Any ) -> ClauseElement : ...
260
240
def nulls_first_op (a : Any ) -> ClauseElement : ...
261
-
262
- nullsfirst_op = nulls_first_op
263
-
264
241
def nulls_last_op (a : Any ) -> ClauseElement : ...
265
-
266
- nullslast_op = nulls_last_op
267
-
268
- def json_getitem_op (a : Any , b : Any ) -> None : ...
269
- def json_path_getitem_op (a : Any , b : Any ) -> None : ...
242
+ def json_getitem_op (a : Any , b : Any ) -> NoReturn : ...
243
+ def json_path_getitem_op (a : Any , b : Any ) -> NoReturn : ...
270
244
def is_comparison (op : Any ) -> bool : ...
271
245
def is_commutative (op : Any ) -> bool : ...
272
246
def is_ordering_modifier (op : Any ) -> bool : ...
@@ -275,3 +249,19 @@ def is_boolean(op: Any) -> bool: ...
275
249
def mirror (op : Any ) -> Any : ...
276
250
def is_associative (op : Any ) -> bool : ...
277
251
def is_precedent (operator : Any , against : Any ) -> bool : ...
252
+
253
+ # 1.4 deprecated; see sqlalchemy#5435
254
+ istrue = is_true
255
+ isfalse = is_false
256
+ isnot_distinct_from = is_not_distinct_from
257
+ isnot = is_not
258
+ notlike_op = not_like_op
259
+ notilike_op = not_ilike_op
260
+ notbetween_op = not_between_op
261
+ notin_op = not_in_op
262
+ notstartswith_op = not_startswith_op
263
+ notendswith_op = not_endswith_op
264
+ notcontains_op = not_contains_op
265
+ notmatch_op = not_match_op
266
+ nullsfirst_op = nulls_first_op
267
+ nullslast_op = nulls_last_op
0 commit comments