Skip to content

Commit 18c563f

Browse files
authored
Merge pull request #36 from bryanforbes/improve-sql-dml
Improve `sql.dml`
2 parents a546da0 + 9f1686a commit 18c563f

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

sqlalchemy-stubs/sql/dml.pyi

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
from typing import Any
22
from typing import Optional
3+
from typing import TypeVar
4+
from typing import Union
35

4-
from sqlalchemy.types import NullType as NullType
5-
from . import coercions as coercions
6-
from . import roles as roles
7-
from .base import ColumnCollection as ColumnCollection
8-
from .base import CompileState as CompileState
9-
from .base import DialectKWArgs as DialectKWArgs
10-
from .base import Executable as Executable
11-
from .base import HasCompileState as HasCompileState
12-
from .elements import BooleanClauseList as BooleanClauseList
13-
from .elements import ClauseElement as ClauseElement
14-
from .elements import Null as Null
15-
from .selectable import HasCTE as HasCTE
16-
from .selectable import HasPrefixes as HasPrefixes
17-
from .visitors import InternalTraversal as InternalTraversal
18-
from .. import exc as exc
19-
from .. import util as util
20-
from ..util import collections_abc as collections_abc
6+
from . import roles
7+
from .base import CompileState
8+
from .base import DialectKWArgs
9+
from .base import Executable
10+
from .base import HasCompileState
11+
from .base import ImmutableColumnCollection
12+
from .elements import BooleanClauseList
13+
from .elements import ClauseElement
14+
from .schema import Table
15+
from .selectable import HasCTE
16+
from .selectable import HasPrefixes
17+
18+
_UB = TypeVar("_UB", bound=UpdateBase)
19+
_VB = TypeVar("_VB", bound=ValuesBase)
20+
_I = TypeVar("_I", bound=Insert)
21+
_DWB = TypeVar("_DWB", bound=DMLWhereBase)
22+
_UD = TypeVar("_UD", bound=Update)
2123

2224
class DMLState(CompileState):
2325
isupdate: bool = ...
2426
isdelete: bool = ...
2527
isinsert: bool = ...
2628
def __init__(self, statement: Any, compiler: Any, **kw: Any) -> None: ...
2729
@property
28-
def dml_table(self): ...
30+
def dml_table(self) -> Table: ...
2931

3032
class InsertDMLState(DMLState):
3133
isinsert: bool = ...
@@ -37,7 +39,7 @@ class UpdateDMLState(DMLState):
3739
isupdate: bool = ...
3840
include_table_with_column_exprs: bool = ...
3941
statement: Any = ...
40-
is_multitable: Any = ...
42+
is_multitable: bool = ...
4143
def __init__(self, statement: Any, compiler: Any, **kw: Any) -> None: ...
4244

4345
class DeleteDMLState(DMLState):
@@ -57,27 +59,26 @@ class UpdateBase(
5759
__visit_name__: str = ...
5860
named_with_column: bool = ...
5961
is_dml: bool = ...
60-
def params(self, *arg: Any, **kw: Any) -> None: ...
61-
def with_dialect_options(self, **opt: Any) -> None: ...
62-
def bind(self): ...
6362
bind: Any = ...
64-
def returning(self, *cols: Any) -> None: ...
63+
def params(self: _UB, *arg: Any, **kw: Any) -> _UB: ...
64+
def with_dialect_options(self: _UB, **opt: Any) -> _UB: ...
65+
def returning(self: _UB, *cols: Any) -> _UB: ...
6566
@property
66-
def exported_columns(self): ...
67+
def exported_columns(self) -> ImmutableColumnCollection[Any]: ...
6768
def with_hint(
68-
self,
69+
self: _UB,
6970
text: Any,
7071
selectable: Optional[Any] = ...,
7172
dialect_name: str = ...,
72-
) -> None: ...
73+
) -> _UB: ...
7374

7475
class ValuesBase(UpdateBase):
7576
__visit_name__: str = ...
7677
select: Any = ...
7778
table: Any = ...
7879
def __init__(self, table: Any, values: Any, prefixes: Any) -> None: ...
79-
def values(self, *args: Any, **kwargs: Any) -> None: ...
80-
def return_defaults(self, *cols: Any) -> None: ...
80+
def values(self: _VB, *args: Any, **kwargs: Any) -> _VB: ...
81+
def return_defaults(self: _VB, *cols: Any) -> _VB: ...
8182

8283
class Insert(ValuesBase):
8384
__visit_name__: str = ...
@@ -95,17 +96,19 @@ class Insert(ValuesBase):
9596
return_defaults: bool = ...,
9697
**dialect_kw: Any,
9798
) -> None: ...
98-
def inline(self) -> None: ...
99+
def inline(self: _I) -> _I: ...
99100
def from_select(
100-
self, names: Any, select: Any, include_defaults: bool = ...
101-
) -> None: ...
101+
self: _I, names: Any, select: Any, include_defaults: bool = ...
102+
) -> _I: ...
102103

103104
class DMLWhereBase:
104-
def where(self, *whereclause: Any) -> None: ...
105-
def filter(self, *criteria: Any): ...
106-
def filter_by(self, **kwargs: Any): ...
105+
def where(self: _DWB, *whereclause: Any) -> _DWB: ...
106+
def filter(self: _DWB, *criteria: Any) -> _DWB: ...
107+
def filter_by(self: _DWB, **kwargs: Any) -> _DWB: ...
107108
@property
108-
def whereclause(self): ...
109+
def whereclause(
110+
self,
111+
) -> Optional[Union[BooleanClauseList[Any], ClauseElement]]: ...
109112

110113
class Update(DMLWhereBase, ValuesBase):
111114
__visit_name__: str = ...
@@ -123,8 +126,8 @@ class Update(DMLWhereBase, ValuesBase):
123126
preserve_parameter_order: bool = ...,
124127
**dialect_kw: Any,
125128
) -> None: ...
126-
def ordered_values(self, *args: Any) -> None: ...
127-
def inline(self) -> None: ...
129+
def ordered_values(self: _UD, *args: Any) -> _UD: ...
130+
def inline(self: _UD) -> _UD: ...
128131

129132
class Delete(DMLWhereBase, UpdateBase):
130133
__visit_name__: str = ...

0 commit comments

Comments
 (0)