@@ -24,6 +24,7 @@ from typing import NoReturn
24
24
from typing import Optional
25
25
from typing import Type
26
26
from typing import TypeVar
27
+ from typing import overload
27
28
from typing import Union
28
29
29
30
from . import sqltypes
@@ -34,13 +35,15 @@ from .type_api import TypeEngine
34
35
_F = TypeVar ("_F" , bound = Callable [..., Any ])
35
36
_T = TypeVar ("_T" )
36
37
_TE = TypeVar ("_TE" , bound = TypeEngine [Any ])
38
+ _OTE = TypeVar ("_OTE" , bound = TypeEngine [Any ])
39
+ _CE = TypeVar ("_CE" , bound = ClauseElement )
37
40
38
41
div = truediv
39
42
40
- class Operators :
41
- def __and__ (self , other : Any ) -> ClauseElement : ...
42
- def __or__ (self , other : Any ) -> ClauseElement : ...
43
- def __invert__ (self ) -> ClauseElement : ...
43
+ class Operators ( Generic [ _CE ]) :
44
+ def __and__ (self , other : Any ) -> _CE : ...
45
+ def __or__ (self , other : Any ) -> _CE : ...
46
+ def __invert__ (self ) -> _CE : ...
44
47
def op (
45
48
self ,
46
49
opstring : Any ,
@@ -52,13 +55,9 @@ class Operators:
52
55
) -> Callable [[Any ], ClauseElement ]: ...
53
56
def bool_op (
54
57
self , opstring : Any , precedence : int = ...
55
- ) -> Callable [[Any ], ClauseElement ]: ...
56
- def operate (
57
- self , op : Any , * other : Any , ** kwargs : Any
58
- ) -> ClauseElement : ...
59
- def reverse_operate (
60
- self , op : Any , other : Any , ** kwargs : Any
61
- ) -> ClauseElement : ...
58
+ ) -> Callable [[Any ], _CE ]: ...
59
+ def operate (self , op : Any , * other : Any , ** kwargs : Any ) -> _CE : ...
60
+ def reverse_operate (self , op : Any , other : Any , ** kwargs : Any ) -> _CE : ...
62
61
63
62
class custom_op :
64
63
__name__ : str = ...
@@ -83,7 +82,23 @@ class custom_op:
83
82
def __hash__ (self ) -> int : ...
84
83
def __call__ (self , left : Any , right : Any , ** kw : Any ) -> ClauseElement : ...
85
84
86
- class ColumnOperators (Operators , Generic [_TE ]):
85
+ class ColumnOperators (Operators [ColumnElement [_TE ]], Generic [_TE ]):
86
+ # op requires custom override
87
+ @overload
88
+ def op (
89
+ self ,
90
+ opstring : Any ,
91
+ precedence : int = ...,
92
+ is_comparison : bool = ...,
93
+ ) -> Callable [[Any ], ColumnElement [_TE ]]: ...
94
+ @overload
95
+ def op (
96
+ self ,
97
+ opstring : Any ,
98
+ precedence : int = ...,
99
+ is_comparison : bool = ...,
100
+ return_type : Union [Type [_OTE ], _OTE ] = ...,
101
+ ) -> Callable [[Any ], ColumnElement [_OTE ]]: ...
87
102
timetuple : Any = ...
88
103
# TODO https://github.com/sqlalchemy/sqlalchemy2-stubs/issues/114
89
104
# Can we also limit the "other" parameter? Most should be
0 commit comments