1
+ import sys
1
2
from typing import Any
2
- from typing import Int
3
+ from typing import Iterable
3
4
from typing import Iterator
4
5
from typing import List
5
6
from typing import Mapping
6
7
from typing import Optional
8
+ from typing import Tuple
9
+ from typing import TypeVar
7
10
8
- from sqlalchemy .cresultproxy import tuplegetter as tuplegetter
9
11
from .row import Row as Row
10
- from .. import exc as exc
11
- from .. import util as util
12
- from ..sql .base import HasMemoized as HasMemoized
13
- from ..sql .base import InPlaceGenerative as InPlaceGenerative
14
- from ..util import collections_abc as collections_abc
15
- from ..util import py2k as py2k
12
+ from ..sql .base import InPlaceGenerative
13
+ from ..util import collections_abc
14
+
15
+ _TResult = TypeVar ("_TResult" , bound = Result )
16
+ _TScalarResult = TypeVar ("_TScalarResult" , bound = ScalarResult )
17
+ _TMappingResult = TypeVar ("_TMappingResult" , bound = MappingResult )
18
+ _TChunkedIteratorResult = TypeVar (
19
+ "_TChunkedIteratorResult" , bound = ChunkedIteratorResult
20
+ )
16
21
17
22
class ResultMetaData :
18
23
@property
19
- def keys (self ): ...
24
+ def keys (self ) -> RMKeyView : ...
20
25
21
- class RMKeyView (collections_abc .KeysView ):
26
+ class RMKeyView (collections_abc .KeysView [ str ] ):
22
27
def __init__ (self , parent : Any ) -> None : ...
23
- def __len__ (self ): ...
24
- def __iter__ (self ) -> Any : ...
25
- def __contains__ (self , item : Any ) : ...
26
- def __eq__ (self , other : Any ) -> Any : ...
27
- def __ne__ (self , other : Any ) -> Any : ...
28
+ def __len__ (self ) -> int : ...
29
+ def __iter__ (self ) -> Iterator [ str ] : ...
30
+ def __contains__ (self , item : object ) -> bool : ...
31
+ def __eq__ (self , other : Any ) -> bool : ...
32
+ def __ne__ (self , other : Any ) -> bool : ...
28
33
29
34
class SimpleResultMetaData (ResultMetaData ):
30
35
def __init__ (
31
36
self ,
32
- keys : Any ,
37
+ keys : Iterable [ str ] ,
33
38
extra : Optional [Any ] = ...,
34
39
_processors : Optional [Any ] = ...,
35
40
_tuplefilter : Optional [Any ] = ...,
36
41
_translated_indexes : Optional [Any ] = ...,
37
42
_unique_filters : Optional [Any ] = ...,
38
43
) -> None : ...
39
44
40
- def result_tuple (fields : Any , extra : Optional [Any ] = ...): ...
45
+ def result_tuple (fields : Any , extra : Optional [Any ] = ...) -> Row : ...
41
46
42
47
class ResultInternal (InPlaceGenerative ): ...
43
48
44
49
class _WithKeys :
45
- def keys (self ): ...
50
+ def keys (self ) -> RMKeyView : ...
46
51
47
52
class Result (_WithKeys , ResultInternal ):
48
53
def __init__ (self , cursor_metadata : Any ) -> None : ...
49
- def yield_per (self , num : Any ) -> None : ...
50
- def unique (self , strategy : Optional [object ] = ...) -> Result : ...
51
- def columns (self , * col_expressions : object ) -> Result : ...
52
- def scalars (self , index : Int = ...) -> ScalarResult : ...
53
- def mappings (self ): ...
54
- def __iter__ (self ) -> Any : ...
55
- def __next__ (self ): ...
56
- def next (self ): ...
57
- def partitions (self , size : Optional [Int ] = ...) -> Iterator [List [Row ]]: ...
54
+ def yield_per (self : _TResult , num : Any ) -> _TResult : ...
55
+ def unique (
56
+ self : _TResult , strategy : Optional [object ] = ...
57
+ ) -> _TResult : ...
58
+ def columns (self : _TResult , * col_expressions : object ) -> _TResult : ...
59
+ def scalars (self , index : int = ...) -> ScalarResult : ...
60
+ def mappings (self ) -> MappingResult : ...
61
+ def __iter__ (self ) -> Iterator [Row ]: ...
62
+ def __next__ (self ) -> Row : ...
63
+ if sys .version_info < (3 , 0 ):
64
+ def next (self ) -> Row : ...
65
+ def partitions (self , size : Optional [int ] = ...) -> Iterator [List [Row ]]: ...
58
66
def fetchall (self ) -> List [Row ]: ...
59
- def fetchone (self ) -> Row : ...
60
- def fetchmany (self , size : Optional [Int ] = ...) -> List [Row ]: ...
67
+ def fetchone (self ) -> Optional [ Row ] : ...
68
+ def fetchmany (self , size : Optional [int ] = ...) -> List [Row ]: ...
61
69
def all (self ) -> List [Row ]: ...
62
- def first (self ) -> Row : ...
70
+ def first (self ) -> Optional [ Row ] : ...
63
71
def one_or_none (self ) -> Optional [Row ]: ...
64
72
def scalar_one (self ) -> Any : ...
65
73
def scalar_one_or_none (self ) -> Optional [Any ]: ...
66
74
def one (self ) -> Row : ...
67
75
def scalar (self ) -> Optional [Any ]: ...
68
- def freeze (self ): ...
69
- def merge (self , * others : Any ) : ...
76
+ def freeze (self ) -> FrozenResult : ...
77
+ def merge (self , * others : Result ) -> MergedResult : ...
70
78
71
79
class FilterResult (ResultInternal ): ...
72
80
73
81
class ScalarResult (FilterResult ):
74
- def __init__ (self , real_result : Any , index : Any ) -> None : ...
75
- def unique (self , strategy : Optional [Any ] = ...): ...
76
- def partitions (self , size : Optional [Int ] = ...) -> Iterator [List [Any ]]: ...
82
+ def __init__ (self , real_result : Result , index : Any ) -> None : ...
83
+ def unique (
84
+ self : _TScalarResult , strategy : Optional [Any ] = ...
85
+ ) -> _TScalarResult : ...
86
+ def partitions (self , size : Optional [int ] = ...) -> Iterator [List [Any ]]: ...
77
87
def fetchall (self ) -> List [Any ]: ...
78
- def fetchmany (self , size : Optional [Int ] = ...) -> List [Any ]: ...
88
+ def fetchmany (self , size : Optional [int ] = ...) -> List [Any ]: ...
79
89
def all (self ) -> List [Any ]: ...
80
- def __iter__ (self ) -> Any : ...
81
- def __next__ (self ): ...
82
- def next (self ): ...
90
+ def __iter__ (self ) -> Iterator [Any ]: ...
91
+ def __next__ (self ) -> Any : ...
92
+ if sys .version_info < (3 , 0 ):
93
+ def next (self ) -> Any : ...
83
94
def first (self ) -> Optional [Any ]: ...
84
95
def one_or_none (self ) -> Optional [Any ]: ...
85
96
def one (self ) -> Any : ...
86
97
87
98
class MappingResult (_WithKeys , FilterResult ):
88
- def __init__ (self , result : Any ) -> None : ...
89
- def unique (self , strategy : Optional [Any ] = ...): ...
90
- def columns (self , * col_expressions : object ) -> MappingResult : ...
99
+ def __init__ (self , result : Result ) -> None : ...
100
+ def unique (
101
+ self : _TMappingResult , strategy : Optional [Any ] = ...
102
+ ) -> _TMappingResult : ...
103
+ def columns (
104
+ self : _TMappingResult , * col_expressions : object
105
+ ) -> _TMappingResult : ...
91
106
def partitions (
92
- self , size : Optional [Int ] = ...
93
- ) -> Iterator [List [Mapping ]]: ...
94
- def fetchall (self ) -> List [Mapping ]: ...
95
- def fetchone (self ) -> Mapping : ...
96
- def fetchmany (self , size : Optional [Int ] = ...) -> List [Mapping ]: ...
97
- def all (self ) -> List [Mapping ]: ...
98
- def __iter__ (self ) -> Any : ...
99
- def __next__ (self ): ...
100
- def next (self ): ...
101
- def first (self ) -> Optional [Mapping ]: ...
102
- def one_or_none (self ) -> Optional [Mapping ]: ...
103
- def one (self ) -> Mapping : ...
107
+ self , size : Optional [int ] = ...
108
+ ) -> Iterator [List [Mapping [Any , Any ]]]: ...
109
+ def fetchall (self ) -> List [Mapping [Any , Any ]]: ...
110
+ def fetchone (self ) -> Mapping [Any , Any ]: ...
111
+ def fetchmany (
112
+ self , size : Optional [int ] = ...
113
+ ) -> List [Mapping [Any , Any ]]: ...
114
+ def all (self ) -> List [Mapping [Any , Any ]]: ...
115
+ def __iter__ (self ) -> Iterator [Mapping [Any , Any ]]: ...
116
+ def __next__ (self ) -> Mapping [Any , Any ]: ...
117
+ if sys .version_info < (3 , 0 ):
118
+ def next (self ) -> Mapping [Any , Any ]: ...
119
+ def first (self ) -> Optional [Mapping [Any , Any ]]: ...
120
+ def one_or_none (self ) -> Optional [Mapping [Any , Any ]]: ...
121
+ def one (self ) -> Mapping [Any , Any ]: ...
104
122
105
123
class FrozenResult :
106
124
metadata : Any = ...
107
125
data : Any = ...
108
- def __init__ (self , result : Any ) -> None : ...
109
- def rewrite_rows (self ): ...
110
- def with_new_rows (self , tuple_data : Any ): ...
111
- def __call__ (self ): ...
126
+ def __init__ (self , result : Result ) -> None : ...
127
+ def rewrite_rows (self ) -> List [List [Any ]]: ...
128
+ def with_new_rows (
129
+ self , tuple_data : List [Tuple [Any , ...]]
130
+ ) -> FrozenResult : ...
131
+ def __call__ (self ) -> IteratorResult : ...
112
132
113
133
class IteratorResult (Result ):
114
134
iterator : Any = ...
@@ -117,7 +137,7 @@ class IteratorResult(Result):
117
137
self , cursor_metadata : Any , iterator : Any , raw : Optional [Any ] = ...
118
138
) -> None : ...
119
139
120
- def null_result (): ...
140
+ def null_result () -> IteratorResult : ...
121
141
122
142
class ChunkedIteratorResult (IteratorResult ):
123
143
chunks : Any = ...
@@ -132,9 +152,11 @@ class ChunkedIteratorResult(IteratorResult):
132
152
raw : Optional [Any ] = ...,
133
153
dynamic_yield_per : bool = ...,
134
154
) -> None : ...
135
- def yield_per (self , num : Any ) -> None : ...
155
+ def yield_per (
156
+ self : _TChunkedIteratorResult , num : Any
157
+ ) -> _TChunkedIteratorResult : ...
136
158
137
159
class MergedResult (IteratorResult ):
138
160
closed : bool = ...
139
- def __init__ (self , cursor_metadata : Any , results : Any ) -> None : ...
161
+ def __init__ (self , cursor_metadata : Any , results : Result ) -> None : ...
140
162
def close (self ) -> None : ...
0 commit comments