1
- from typing import Any , Optional , Union
1
+ from typing import Any , Optional , Union , TypeVar , Generic , List , Iterator
2
2
from . import interfaces
3
3
from .base import InspectionAttr
4
- from ..sql .selectable import ForUpdateArg
4
+ from ..sql .selectable import ForUpdateArg , Alias , CTE
5
+ from ..sql .elements import Label
6
+ from .session import Session
5
7
6
- class Query (object ):
7
- session : Any = ...
8
- def __init__ (self , entities , session : Optional [Any ] = ...) -> None : ...
8
+
9
+ _T = TypeVar ('_T' )
10
+ _Q = TypeVar ('_Q' , bound = "Query" )
11
+
12
+
13
+ class Query (Generic [_T ]):
14
+ session : Session = ...
15
+ def __init__ (self , entities , session : Optional [Session ] = ...) -> None : ...
16
+
17
+ # TODO: is "statement" always of type sqlalchemy.sql.selectable.Select ?
9
18
@property
10
19
def statement (self ): ...
11
- def subquery (self , name : Optional [Any ] = ..., with_labels : bool = ..., reduce_columns : bool = ...): ...
12
- def cte (self , name : Optional [Any ] = ..., recursive : bool = ...): ...
13
- def label (self , name ) : ...
20
+ def subquery (self , name : Optional [str ] = ..., with_labels : bool = ..., reduce_columns : bool = ...) -> Alias : ...
21
+ def cte (self , name : Optional [str ] = ..., recursive : bool = ...) -> CTE : ...
22
+ def label (self , name : str ) -> Label : ...
14
23
def as_scalar (self ): ...
15
24
@property
16
25
def selectable (self ): ...
17
26
def __clause_element__ (self ): ...
18
- def enable_eagerloads (self , value ) : ...
19
- def with_labels (self ) : ...
20
- def enable_assertions (self , value ) : ...
27
+ def enable_eagerloads (self : _Q , value : bool ) -> _Q : ...
28
+ def with_labels (self : _Q ) -> _Q : ...
29
+ def enable_assertions (self : _Q , value : bool ) -> _Q : ...
21
30
@property
22
31
def whereclause (self ): ...
23
32
def with_polymorphic (self , cls_or_mappers , selectable : Optional [Any ] = ...,
24
33
polymorphic_on : Optional [Any ] = ...): ...
25
- def yield_per (self , count ) : ...
26
- def get (self , ident ): ...
34
+ def yield_per (self : _Q , count : int ) -> _Q : ...
35
+ def get (self , ident ) -> Optional [ _T ] : ...
27
36
def correlate (self , * args ): ...
28
- def autoflush (self , setting ) : ...
29
- def populate_existing (self ) : ...
37
+ def autoflush (self : _Q , setting : bool ) -> _Q : ...
38
+ def populate_existing (self : _Q ) -> _Q : ...
30
39
def with_parent (self , instance , property : Optional [Any ] = ...): ...
31
40
def add_entity (self , entity , alias : Optional [Any ] = ...): ...
32
- def with_session (self , session ) : ...
41
+ def with_session (self : _Q , session : Optional [ Session ]) -> _Q : ...
33
42
def from_self (self , * entities ): ...
34
43
def values (self , * columns ): ...
35
44
def value (self , column ): ...
@@ -42,14 +51,14 @@ class Query(object):
42
51
def with_statement_hint (self , text , dialect_name : str = ...): ...
43
52
def execution_options (self , ** kwargs ): ...
44
53
def with_lockmode (self , mode ): ...
45
- def with_for_update (self , read : bool = ..., nowait : bool = ..., of : Optional [Any ] = ...,
46
- skip_locked : bool = ..., key_share : bool = ...): ...
47
- def params (self , * args , ** kwargs ): ...
48
- def filter (self , * criterion ): ...
49
- def filter_by (self , ** kwargs ): ...
50
- def order_by (self , * criterion ): ...
51
- def group_by (self , * criterion ): ...
52
- def having (self , criterion ): ...
54
+ def with_for_update (self : _Q , read : bool = ..., nowait : bool = ..., of : Optional [Any ] = ...,
55
+ skip_locked : bool = ..., key_share : bool = ...) -> _Q : ...
56
+ def params (self : _Q , * args , ** kwargs ) -> _Q : ...
57
+ def filter (self : _Q , * criterion ) -> _Q : ...
58
+ def filter_by (self : _Q , ** kwargs ) -> _Q : ...
59
+ def order_by (self : _Q , * criterion ) -> _Q : ...
60
+ def group_by (self : _Q , * criterion ) -> _Q : ...
61
+ def having (self : _Q , criterion ) -> _Q : ...
53
62
def union (self , * q ): ...
54
63
def union_all (self , * q ): ...
55
64
def intersect (self , * q ): ...
@@ -62,26 +71,26 @@ class Query(object):
62
71
def select_from (self , * from_obj ): ...
63
72
def select_entity_from (self , from_obj ): ...
64
73
def __getitem__ (self , item ): ...
65
- def slice (self , start , stop ) : ...
66
- def limit (self , limit ) : ...
67
- def offset (self , offset ) : ...
74
+ def slice (self : _Q , start : Optional [ int ] , stop : Optional [ int ]) -> _Q : ...
75
+ def limit (self : _Q , limit : Optional [ int ]) -> _Q : ...
76
+ def offset (self : _Q , offset : Optional [ int ]) -> _Q : ...
68
77
def distinct (self , * criterion ): ...
69
78
def prefix_with (self , * prefixes ): ...
70
79
def suffix_with (self , * suffixes ): ...
71
- def all (self ): ...
80
+ def all (self ) -> List [ _T ] : ...
72
81
def from_statement (self , statement ): ...
73
- def first (self ): ...
74
- def one_or_none (self ): ...
75
- def one (self ): ...
82
+ def first (self ) -> Optional [ _T ] : ...
83
+ def one_or_none (self ) -> Optional [ _T ] : ...
84
+ def one (self ) -> _T : ...
76
85
def scalar (self ): ...
77
- def __iter__ (self ): ...
86
+ def __iter__ (self ) -> Iterator [ _T ] : ...
78
87
@property
79
88
def column_descriptions (self ): ...
80
89
def instances (self , cursor , __context : Optional [Any ] = ...): ...
81
90
def merge_result (self , iterator , load : bool = ...): ...
82
91
def exists (self ): ...
83
- def count (self ): ...
84
- def delete (self , synchronize_session : Union [bool , str ] = ...): ...
92
+ def count (self ) -> int : ...
93
+ def delete (self , synchronize_session : Union [bool , str ] = ...) -> int : ...
85
94
def update (self , values , synchronize_session : Union [bool , str ] = ..., update_args : Optional [Any ] = ...): ...
86
95
87
96
class LockmodeArg (ForUpdateArg ):
0 commit comments