1- from typing import Any , Optional , Union , List , Dict , TypeVar , Generic , Sequence , Callable , Tuple
1+ from typing import Any , Optional , Union , List , Dict , TypeVar , Generic , Sequence , Callable , Tuple , Set
22from typing_extensions import Protocol
33from .elements import ClauseElement as ClauseElement , ColumnElement
44from .base import Executable as Executable , SchemaVisitor as SchemaVisitor
55from .schema import Table , MetaData , SchemaItem , ForeignKeyConstraint , ForeignKey
66from .compiler import IdentifierPreparer
77from .type_api import TypeEngine
8- from .. import engine
8+ from ..engine import Dialect , Engine , Connection , ResultProxy , Connectable
99
1010_T = TypeVar ('_T' )
1111
1212class _DDLCompiles (ClauseElement ): ...
1313
1414class _DDLCallable (Protocol ):
15- def __call__ (self , ddl : DDLElement , target : Optional [Union [Table , MetaData ]], bind : engine . Connection ,
15+ def __call__ (self , ddl : DDLElement , target : Optional [Union [Table , MetaData ]], bind : Connection ,
1616 tables : Optional [List [Any ]] = ..., state : Optional [Any ] = ...,
1717 checkfirst : bool = ...) -> bool : ...
1818
1919class _DDLOnCallback (Protocol ):
2020 def __call__ (self , ddl : DDLElement , event : Optional [str ], target : Optional [Union [Table , MetaData ]],
21- connection : engine . Connection , tables : Optional [List [Any ]] = ...) -> bool : ...
21+ connection : Connection , tables : Optional [List [Any ]] = ...) -> bool : ...
2222
2323_DDLE = TypeVar ('_DDLE' , bound = DDLElement )
2424
2525class DDLElement (Executable , _DDLCompiles ):
2626 target : Optional [SchemaItem ] = ...
2727 on : Optional [Union [str , Tuple [str , ...], _DDLOnCallback ]] = ...
28- dialect : Optional [engine . Dialect ] = ...
28+ dialect : Optional [Dialect ] = ...
2929 callable_ : Optional [_DDLCallable ] = ...
30- bind : Optional [engine . Connection ] = ...
31- def execute (self , bind : Optional [engine . Connectable ] = ..., # type: ignore # incompatible with Executable.execute
32- target : Optional [SchemaItem ] = ...) -> Optional [engine . ResultProxy ]: ...
30+ bind : Optional [Union [ Engine , Connection ] ] = ...
31+ def execute (self , bind : Optional [Union [ Engine , Connection ] ] = ..., # type: ignore # incompatible with Executable.execute
32+ target : Optional [SchemaItem ] = ...) -> Optional [ResultProxy ]: ...
3333 def execute_at (self , event_name : str , target : SchemaItem ) -> None : ...
3434 def against (self : _DDLE , target : SchemaItem ) -> _DDLE : ...
3535 state : Any = ...
36- def execute_if (self : _DDLE , dialect : Optional [engine . Dialect ] = ..., callable_ : Optional [_DDLCallable ] = ...,
36+ def execute_if (self : _DDLE , dialect : Optional [Dialect ] = ..., callable_ : Optional [_DDLCallable ] = ...,
3737 state : Optional [Any ] = ...) -> _DDLE : ...
38- def __call__ (self , target , bind , ** kw ) : ...
38+ def __call__ (self , target : Optional [ Union [ Table , MetaData ]], bind : Connection , ** kw : Any ) -> Optional [ ResultProxy ] : ...
3939
4040class DDL (DDLElement ):
4141 __visit_name__ : str = ...
4242 statement : str = ...
4343 context : Dict [Any , Any ] = ...
4444 on : Optional [Union [str , Tuple [str , ...], _DDLOnCallback ]] = ...
4545 def __init__ (self , statement : str , on : Optional [Union [str , Tuple [str , ...], _DDLOnCallback ]] = ...,
46- context : Optional [Dict [Any , Any ]] = ..., bind : Optional [engine . Connectable ] = ...) -> None : ...
46+ context : Optional [Dict [Any , Any ]] = ..., bind : Optional [Connectable ] = ...) -> None : ...
4747
4848class _CreateDropBase (DDLElement , Generic [_T ]):
4949 element : _T = ...
50- bind : Optional [engine . Connection ] = ...
50+ bind : Optional [Connection ] = ...
5151 def __init__ (self , element : _T , on : Optional [Union [str , Tuple [str , ...], _DDLOnCallback ]] = ...,
52- bind : Optional [engine . Connection ] = ...) -> None : ...
52+ bind : Optional [Connection ] = ...) -> None : ...
5353
5454class CreateSchema (_CreateDropBase [str ]):
5555 __visit_name__ : str = ...
@@ -67,7 +67,7 @@ class CreateTable(_CreateDropBase[Table]):
6767 columns : List [CreateColumn [Any ]] = ...
6868 include_foreign_key_constraints : Optional [Sequence [ForeignKeyConstraint ]] = ...
6969 def __init__ (self , element : Table , on : Optional [Union [str , Tuple [str , ...], _DDLOnCallback ]] = ...,
70- bind : Optional [engine . Connectable ] = ...,
70+ bind : Optional [Connectable ] = ...,
7171 include_foreign_key_constraints : Optional [Sequence [ForeignKeyConstraint ]] = ...) -> None : ...
7272
7373class _DropView (_CreateDropBase [str ]):
@@ -100,19 +100,19 @@ class AddConstraint(_CreateDropBase[str]):
100100class DropConstraint (_CreateDropBase [str ]):
101101 __visit_name__ : str = ...
102102 cascade : bool = ...
103- def __init__ (self , element : str , cascade : bool = ..., ** kw ) -> None : ...
103+ def __init__ (self , element : str , cascade : bool = ..., ** kw : Any ) -> None : ...
104104
105105class DDLBase (SchemaVisitor ):
106- connection : engine . Connection = ...
107- def __init__ (self , connection : engine . Connection ) -> None : ...
106+ connection : Connection = ...
107+ def __init__ (self , connection : Connection ) -> None : ...
108108
109109class SchemaGenerator (DDLBase ):
110110 checkfirst : bool = ...
111111 tables : Optional [List [Table ]] = ...
112112 preparer : IdentifierPreparer = ...
113- dialect : engine . Dialect = ...
113+ dialect : Dialect = ...
114114 memo : Dict [Any , Any ] = ...
115- def __init__ (self , dialect : engine . Dialect , connection : engine . Connection , checkfirst : bool = ...,
115+ def __init__ (self , dialect : Dialect , connection : Connection , checkfirst : bool = ...,
116116 tables : Optional [List [Table ]] = ..., ** kwargs : Any ) -> None : ...
117117 def visit_metadata (self , metadata : MetaData ) -> None : ...
118118 def visit_table (self , table : Table , create_ok : bool = ...,
@@ -126,9 +126,9 @@ class SchemaDropper(DDLBase):
126126 checkfirst : bool = ...
127127 tables : Optional [List [Table ]] = ...
128128 preparer : IdentifierPreparer = ...
129- dialect : engine . Dialect = ...
129+ dialect : Dialect = ...
130130 memo : Dict [Any , Any ] = ...
131- def __init__ (self , dialect : engine . Dialect , connection : engine . Connection , checkfirst : bool = ...,
131+ def __init__ (self , dialect : Dialect , connection : Connection , checkfirst : bool = ...,
132132 tables : Optional [List [Table ]] = ..., ** kwargs : Any ) -> None : ...
133133 def visit_metadata (self , metadata : MetaData ) -> None : ...
134134 def visit_index (self , index : str ) -> None : ...
@@ -137,7 +137,11 @@ class SchemaDropper(DDLBase):
137137 def visit_sequence (self , sequence : str , drop_ok : bool = ...) -> None : ...
138138
139139def sort_tables (tables : Sequence [Table ], skip_fn : Optional [Callable [[ForeignKey ], bool ]] = ...,
140- extra_dependencies : Optional [Sequence [Tuple [Table , Table ]]] = ...): ...
140+ extra_dependencies : Optional [Sequence [Tuple [Table , Table ]]] = ...) -> List [Table ]: ...
141+
142+
143+ _SortResultType = List [Tuple [Optional [Table ], Union [Set [ForeignKeyConstraint ], List [ForeignKeyConstraint ]]]]
144+
141145def sort_tables_and_constraints (tables : Sequence [Table ],
142146 filter_fn : Optional [Callable [[ForeignKeyConstraint ], Optional [bool ]]] = ...,
143- extra_dependencies : Optional [Sequence [Tuple [Table , Table ]]] = ...): ...
147+ extra_dependencies : Optional [Sequence [Tuple [Table , Table ]]] = ...) -> _SortResultType : ...
0 commit comments