1
1
from typing import Any
2
+ from typing import Callable
3
+ from typing import Dict
4
+ from typing import Iterable
5
+ from typing import List
2
6
from typing import Optional
7
+ from typing import Sequence
8
+ from typing import Set
9
+ from typing import Tuple
10
+ from typing import TypeVar
11
+ from typing import Union
3
12
4
- from . import roles as roles
5
- from .base import Executable as Executable
6
- from .base import SchemaVisitor as SchemaVisitor
7
- from .elements import ClauseElement as ClauseElement
8
- from .. import exc as exc
9
- from .. import util as util
10
- from ..util import topological as topological
13
+ from typing_extensions import Protocol
14
+
15
+ from . import roles
16
+ from .base import Executable
17
+ from .base import SchemaVisitor
18
+ from .elements import ClauseElement
19
+ from .schema import ForeignKey
20
+ from .schema import ForeignKeyConstraint
21
+ from .schema import Index
22
+ from .schema import SchemaItem
23
+ from .schema import Table
24
+ from ..engine import Connection
25
+ from ..engine import Dialect
26
+ from ..engine import Engine
27
+
28
+ _DDLE = TypeVar ("_DDLE" , bound = DDLElement )
29
+
30
+ _Bind = Union [Engine , Connection ]
31
+
32
+ class _DDLElementCallback (Protocol ):
33
+ def __call__ (
34
+ self ,
35
+ __ddl : DDLElement ,
36
+ __target : Optional [SchemaItem ],
37
+ __bind : _Bind ,
38
+ * ,
39
+ state : Optional [Any ],
40
+ ** kw : Any ,
41
+ ) -> bool : ...
11
42
12
43
class _DDLCompiles (ClauseElement ): ...
13
44
14
45
class DDLElement (roles .DDLRole , Executable , _DDLCompiles ):
15
- target : Any = ...
46
+ target : Optional [ SchemaItem ] = ...
16
47
on : Any = ...
17
- dialect : Any = ...
18
- callable_ : Any = ...
19
- def execute (
20
- self , bind : Optional [Any ] = ..., target : Optional [Any ] = ...
21
- ): ...
22
- def against (self , target : Any ) -> None : ...
23
- state : Any = ...
24
- def execute_if (
48
+ dialect : Union [str , Tuple [str , ...], List [str ], Set [str ], None ] = ...
49
+ callable_ : Optional [_DDLElementCallback ] = ...
50
+ state : Optional [Any ] = ...
51
+ bind : Optional [_Bind ] = ...
52
+ def execute ( # type: ignore[override]
25
53
self ,
26
- dialect : Optional [Any ] = ...,
27
- callable_ : Optional [Any ] = ...,
54
+ bind : Optional [_Bind ] = ...,
55
+ target : Optional [SchemaItem ] = ...,
56
+ ) -> Any : ...
57
+ def against (self : _DDLE , target : Optional [SchemaItem ]) -> _DDLE : ...
58
+ def execute_if (
59
+ self : _DDLE ,
60
+ dialect : Optional [
61
+ Union [str , Tuple [str , ...], List [str ], Set [str ]]
62
+ ] = ...,
63
+ callable_ : Optional [_DDLElementCallback ] = ...,
28
64
state : Optional [Any ] = ...,
29
- ) -> None : ...
30
- def __call__ (self , target : Any , bind : Any , ** kw : Any ): ...
31
- def bind ( self ): ...
32
- bind : Any = ...
65
+ ) -> _DDLE : ...
66
+ def __call__ (
67
+ self , target : SchemaItem , bind : _Bind , ** kw : Any
68
+ ) -> Optional [ Any ]: ...
33
69
34
70
class DDL (DDLElement ):
35
71
__visit_name__ : str = ...
36
- statement : Any = ...
72
+ statement : str = ...
37
73
context : Any = ...
38
74
def __init__ (
39
75
self ,
40
- statement : Any ,
41
- context : Optional [Any ] = ...,
42
- bind : Optional [Any ] = ...,
76
+ statement : str ,
77
+ context : Optional [Dict [ str , Any ] ] = ...,
78
+ bind : Optional [_Bind ] = ...,
43
79
) -> None : ...
44
80
45
81
class _CreateDropBase (DDLElement ):
46
82
element : Any = ...
47
- bind : Any = ...
48
- if_exists : Any = ...
49
- if_not_exists : Any = ...
83
+ if_exists : bool = ...
84
+ if_not_exists : bool = ...
50
85
def __init__ (
51
86
self ,
52
87
element : Any ,
53
- bind : Optional [Any ] = ...,
88
+ bind : Optional [_Bind ] = ...,
54
89
if_exists : bool = ...,
55
90
if_not_exists : bool = ...,
56
91
_legacy_bind : Optional [Any ] = ...,
57
92
) -> None : ...
58
93
@property
59
- def stringify_dialect (self ): ...
94
+ def stringify_dialect (self ) -> str : ... # type: ignore[override]
60
95
61
96
class CreateSchema (_CreateDropBase ):
62
97
__visit_name__ : str = ...
63
98
quote : Any = ...
64
99
def __init__ (
65
- self , name : Any , quote : Optional [Any ] = ..., ** kw : Any
100
+ self , name : str , quote : Optional [Any ] = ..., ** kw : Any
66
101
) -> None : ...
67
102
68
103
class DropSchema (_CreateDropBase ):
@@ -71,7 +106,7 @@ class DropSchema(_CreateDropBase):
71
106
cascade : Any = ...
72
107
def __init__ (
73
108
self ,
74
- name : Any ,
109
+ name : str ,
75
110
quote : Optional [Any ] = ...,
76
111
cascade : bool = ...,
77
112
** kw : Any ,
@@ -83,9 +118,11 @@ class CreateTable(_CreateDropBase):
83
118
include_foreign_key_constraints : Any = ...
84
119
def __init__ (
85
120
self ,
86
- element : Any ,
87
- bind : Optional [Any ] = ...,
88
- include_foreign_key_constraints : Optional [Any ] = ...,
121
+ element : Table ,
122
+ bind : Optional [_Bind ] = ...,
123
+ include_foreign_key_constraints : Optional [
124
+ Sequence [ForeignKeyConstraint ]
125
+ ] = ...,
89
126
if_not_exists : bool = ...,
90
127
) -> None : ...
91
128
@@ -100,7 +137,10 @@ class CreateColumn(_DDLCompiles):
100
137
class DropTable (_CreateDropBase ):
101
138
__visit_name__ : str = ...
102
139
def __init__ (
103
- self , element : Any , bind : Optional [Any ] = ..., if_exists : bool = ...
140
+ self ,
141
+ element : Table ,
142
+ bind : Optional [_Bind ] = ...,
143
+ if_exists : bool = ...,
104
144
) -> None : ...
105
145
106
146
class CreateSequence (_CreateDropBase ):
@@ -113,15 +153,18 @@ class CreateIndex(_CreateDropBase):
113
153
__visit_name__ : str = ...
114
154
def __init__ (
115
155
self ,
116
- element : Any ,
117
- bind : Optional [Any ] = ...,
156
+ element : Index ,
157
+ bind : Optional [_Bind ] = ...,
118
158
if_not_exists : bool = ...,
119
159
) -> None : ...
120
160
121
161
class DropIndex (_CreateDropBase ):
122
162
__visit_name__ : str = ...
123
163
def __init__ (
124
- self , element : Any , bind : Optional [Any ] = ..., if_exists : bool = ...
164
+ self ,
165
+ element : Index ,
166
+ bind : Optional [_Bind ] = ...,
167
+ if_exists : bool = ...,
125
168
) -> None : ...
126
169
127
170
class AddConstraint (_CreateDropBase ):
@@ -155,11 +198,11 @@ class SchemaGenerator(DDLBase):
155
198
checkfirst : Any = ...
156
199
tables : Any = ...
157
200
preparer : Any = ...
158
- dialect : Any = ...
201
+ dialect : Dialect = ...
159
202
memo : Any = ...
160
203
def __init__ (
161
204
self ,
162
- dialect : Any ,
205
+ dialect : Dialect ,
163
206
connection : Any ,
164
207
checkfirst : bool = ...,
165
208
tables : Optional [Any ] = ...,
@@ -181,17 +224,17 @@ class SchemaDropper(DDLBase):
181
224
checkfirst : Any = ...
182
225
tables : Any = ...
183
226
preparer : Any = ...
184
- dialect : Any = ...
227
+ dialect : Dialect = ...
185
228
memo : Any = ...
186
229
def __init__ (
187
230
self ,
188
- dialect : Any ,
231
+ dialect : Dialect ,
189
232
connection : Any ,
190
233
checkfirst : bool = ...,
191
234
tables : Optional [Any ] = ...,
192
235
** kwargs : Any ,
193
236
) -> None : ...
194
- def visit_metadata (self , metadata : Any ): ...
237
+ def visit_metadata (self , metadata : Any ) -> None : ...
195
238
def visit_index (self , index : Any , drop_ok : bool = ...) -> None : ...
196
239
def visit_table (
197
240
self ,
@@ -203,13 +246,15 @@ class SchemaDropper(DDLBase):
203
246
def visit_sequence (self , sequence : Any , drop_ok : bool = ...) -> None : ...
204
247
205
248
def sort_tables (
206
- tables : Any ,
207
- skip_fn : Optional [Any ] = ...,
208
- extra_dependencies : Optional [Any ] = ...,
209
- ): ...
249
+ tables : Iterable [ Table ] ,
250
+ skip_fn : Optional [Callable [[ ForeignKey ], bool ] ] = ...,
251
+ extra_dependencies : Optional [Iterable [ Tuple [ Table , Table ]] ] = ...,
252
+ ) -> List [ Table ] : ...
210
253
def sort_tables_and_constraints (
211
- tables : Any ,
212
- filter_fn : Optional [Any ] = ...,
213
- extra_dependencies : Optional [Any ] = ...,
254
+ tables : Iterable [Table ],
255
+ filter_fn : Optional [
256
+ Callable [[ForeignKeyConstraint ], Optional [bool ]]
257
+ ] = ...,
258
+ extra_dependencies : Optional [Iterable [Tuple [Table , Table ]]] = ...,
214
259
_warn_for_cycles : bool = ...,
215
- ): ...
260
+ ) -> List [ Tuple [ Optional [ Table ], List [ ForeignKeyConstraint ]]] : ...
0 commit comments