Skip to content

Commit 69cd00c

Browse files
author
Frederic Morin
committed
stricter type checking
1 parent 7e05bb1 commit 69cd00c

File tree

4 files changed

+97
-38
lines changed

4 files changed

+97
-38
lines changed

sqlalchemy-stubs/dialects/postgresql/dml.pyi

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
1-
from typing import Any
2-
from typing import Mapping
3-
from typing import Optional
4-
from typing import Sequence
5-
from typing import Union
6-
7-
from . import ExcludeConstraint
81
from ... import Column
92
from ... import Constraint
103
from ... import Index
114
from ... import util as util
5+
from ...orm import Mapped
6+
from ...sql import ColumnCollection
127
from ...sql.dml import Insert as StandardInsert
138
from ...sql.elements import ClauseElement
149
from ...sql.elements import ColumnElement
1510
from ...sql.functions import GenericFunction
11+
from . import ExcludeConstraint
12+
13+
from typing import Any
14+
from typing import Mapping
15+
from typing import Optional
16+
from typing import Sequence
17+
from typing import Union
1618

1719
class Insert(StandardInsert):
1820
stringify_dialect: str = ...
21+
# FLARE OVERRIDE
1922
@util.memoized_property
20-
def excluded(self): ...
23+
def excluded(self) -> ColumnCollection: ...
2124
def on_conflict_do_update(
2225
self,
2326
constraint: Optional[
2427
Union[str, Index, Constraint, ExcludeConstraint]
2528
] = ...,
2629
index_elements: Sequence[Union[str, Column]] = ...,
2730
index_where: Optional[ClauseElement] = ...,
28-
set_: Mapping[str, Union[ColumnElement, GenericFunction]] = ...,
31+
# FLARE OVERRIDE
32+
set_: (
33+
Mapping[object, Any]
34+
| Mapping[Mapped, Union[ColumnElement, GenericFunction]]
35+
| Mapping[ColumnElement, Union[ColumnElement, GenericFunction]]
36+
) = ...,
2937
where: Optional[ClauseElement] = ...,
3038
) -> "Insert": ...
3139
def on_conflict_do_nothing(
@@ -67,6 +75,11 @@ class OnConflictDoUpdate(OnConflictClause):
6775
] = ...,
6876
index_elements: Optional[Sequence[Union[str, Column]]] = ...,
6977
index_where: Optional[Any] = ...,
70-
set_: Mapping[str, Union[ColumnElement, GenericFunction]] = ...,
78+
# FLARE OVERRIDE
79+
set_: (
80+
Mapping[object, Any]
81+
| Mapping[Mapped, Union[ColumnElement, GenericFunction]]
82+
| Mapping[ColumnElement, Union[ColumnElement, GenericFunction]]
83+
) = ...,
7184
where: Optional[ClauseElement] = ...,
7285
) -> None: ...

sqlalchemy-stubs/dialects/sqlite/dml.pyi

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
from typing import Any
2-
from typing import Optional
3-
41
from ... import util as util
2+
from ...orm import Mapped
3+
from ...sql import ColumnCollection
54
from ...sql.dml import Insert as StandardInsert
65
from ...sql.elements import ClauseElement
6+
from ...sql.elements import ColumnElement
7+
from ...sql.functions import GenericFunction
8+
9+
from typing import Any
10+
from typing import Mapping
11+
from typing import Optional
12+
from typing import Union
713

814
class Insert(StandardInsert):
915
stringify_dialect: str = ...
16+
# FLARE OVERRIDE
1017
@util.memoized_property
11-
def excluded(self): ...
18+
def excluded(self) -> ColumnCollection: ...
1219
def on_conflict_do_update(
1320
self,
1421
index_elements: Optional[Any] = ...,
1522
index_where: Optional[Any] = ...,
16-
set_: Optional[Any] = ...,
23+
# FLARE OVERRIDE
24+
set_: (
25+
Mapping[object, Any]
26+
| Mapping[Mapped, Union[ColumnElement, GenericFunction]]
27+
| Mapping[ColumnElement, Union[ColumnElement, GenericFunction]]
28+
) = ...,
1729
where: Optional[Any] = ...,
1830
) -> None: ...
1931
def on_conflict_do_nothing(
@@ -46,6 +58,11 @@ class OnConflictDoUpdate(OnConflictClause):
4658
self,
4759
index_elements: Optional[Any] = ...,
4860
index_where: Optional[Any] = ...,
49-
set_: Optional[Any] = ...,
61+
# FLARE OVERRIDE
62+
set_: (
63+
Mapping[object, Any]
64+
| Mapping[Mapped, Union[ColumnElement, GenericFunction]]
65+
| Mapping[ColumnElement, Union[ColumnElement, GenericFunction]]
66+
) = ...,
5067
where: Optional[Any] = ...,
5168
) -> None: ...

sqlalchemy-stubs/sql/base.pyi

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1+
from .. import util
2+
from ..engine import Connection
3+
from ..engine import Engine
4+
from ..util import HasMemoized as HasMemoized
5+
from ..util import langhelpers
6+
from . import roles
7+
from .elements import ColumnElement
8+
from .traversals import HasCacheKey
9+
from .traversals import HasCopyInternals
10+
from .visitors import ClauseVisitor
111
from types import ModuleType
12+
213
from typing import Any
314
from typing import Callable
415
from typing import Dict
@@ -9,22 +20,11 @@ from typing import List
920
from typing import Mapping
1021
from typing import NoReturn
1122
from typing import Optional
12-
from typing import overload
1323
from typing import Tuple
1424
from typing import Type
1525
from typing import TypeVar
1626
from typing import Union
17-
18-
from . import roles
19-
from .elements import ColumnElement
20-
from .traversals import HasCacheKey
21-
from .traversals import HasCopyInternals
22-
from .visitors import ClauseVisitor
23-
from .. import util
24-
from ..engine import Connection
25-
from ..engine import Engine
26-
from ..util import HasMemoized as HasMemoized
27-
from ..util import langhelpers
27+
from typing import overload
2828

2929
_T = TypeVar("_T")
3030
_SC = TypeVar("_SC", bound=SingletonConstant)
@@ -155,7 +155,8 @@ class ColumnCollection(Generic[_CE]):
155155
def __bool__(self) -> bool: ...
156156
def __len__(self) -> int: ...
157157
def __iter__(self) -> Iterator[_CE]: ...
158-
def __getitem__(self, key: str) -> _CE: ...
158+
# FLARE OVERRIDE
159+
# def __getitem__(self, key: str) -> _CE: ...
159160
def __getattr__(self, key: str) -> _CE: ...
160161
def __contains__(self, key: str) -> bool: ...
161162
def compare(self, other: Any) -> bool: ...

sqlalchemy-stubs/sql/dml.pyi

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from typing import Any
2-
from typing import Optional
3-
from typing import TypeVar
4-
from typing import Union
5-
1+
from ..orm import Mapped
2+
from . import ColumnElement
63
from . import roles
74
from .base import CompileState
85
from .base import DialectKWArgs
@@ -15,6 +12,13 @@ from .schema import Table
1512
from .selectable import HasCTE
1613
from .selectable import HasPrefixes
1714

15+
from typing import Any
16+
from typing import Mapping
17+
from typing import Optional
18+
from typing import Sequence
19+
from typing import TypeVar
20+
from typing import Union
21+
1822
_UB = TypeVar("_UB", bound=UpdateBase)
1923
_VB = TypeVar("_VB", bound=ValuesBase)
2024
_I = TypeVar("_I", bound=Insert)
@@ -77,7 +81,16 @@ class ValuesBase(UpdateBase):
7781
select: Any = ...
7882
table: Any = ...
7983
def __init__(self, table: Any, values: Any, prefixes: Any) -> None: ...
80-
def values(self: _VB, *args: Any, **kwargs: Any) -> _VB: ...
84+
# FLARE OVERRIDE
85+
def values(
86+
self: _VB,
87+
*args: Mapping[object, Any]
88+
| Sequence[Mapping[object, Any]]
89+
| Mapping[Mapped[Any], Any]
90+
| Sequence[Mapping[Mapped[Any], Any]]
91+
| Mapping[ColumnElement, Any]
92+
| Sequence[Mapping[ColumnElement, Any]],
93+
) -> _VB: ...
8194
def return_defaults(self: _VB, *cols: Any) -> _VB: ...
8295

8396
class Insert(ValuesBase):
@@ -88,7 +101,15 @@ class Insert(ValuesBase):
88101
def __init__(
89102
self,
90103
table: Any,
91-
values: Optional[Any] = ...,
104+
# FLARE OVERRIDE
105+
values: (
106+
Mapping[object, Any]
107+
| Sequence[Mapping[object, Any]]
108+
| Mapping[Mapped[Any], Any]
109+
| Sequence[Mapping[Mapped[Any], Any]]
110+
| Mapping[ColumnElement, Any]
111+
| Sequence[Mapping[ColumnElement, Any]]
112+
) = ...,
92113
inline: bool = ...,
93114
bind: Optional[Any] = ...,
94115
prefixes: Optional[Any] = ...,
@@ -111,13 +132,20 @@ class DMLWhereBase:
111132
) -> Optional[Union[BooleanClauseList[Any], ClauseElement]]: ...
112133

113134
class Update(DMLWhereBase, ValuesBase):
114-
__visit_name__: str = ...
115135
is_update: bool = ...
116136
def __init__(
117137
self,
118138
table: Any,
119139
whereclause: Optional[Any] = ...,
120-
values: Optional[Any] = ...,
140+
# FLARE OVERRIDE
141+
values: (
142+
Mapping[object, Any]
143+
| Sequence[Mapping[object, Any]]
144+
| Mapping[Mapped[Any], Any]
145+
| Sequence[Mapping[Mapped[Any], Any]]
146+
| Mapping[ColumnElement, Any]
147+
| Sequence[Mapping[ColumnElement, Any]]
148+
) = ...,
121149
inline: bool = ...,
122150
bind: Optional[Any] = ...,
123151
prefixes: Optional[Any] = ...,

0 commit comments

Comments
 (0)