Skip to content

Commit 8f424c9

Browse files
committed
dev
1 parent 768d7c8 commit 8f424c9

File tree

6 files changed

+72
-35
lines changed

6 files changed

+72
-35
lines changed

sqlalchemy-stubs/orm/decl_api.pyi

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from typing import Any
2+
from typing import Generic
23
from typing import Optional
4+
from typing import TypeVar
5+
from typing import Union
36

47
from . import attributes as attributes
58
from . import clsregistry as clsregistry
@@ -8,6 +11,7 @@ from . import interfaces as interfaces
811
from .mapper import Mapper as Mapper
912
from .. import inspection as inspection
1013
from .. import util as util
14+
from ..sql import ColumnElement
1115
from ..sql.schema import MetaData as MetaData
1216
from ..util import hybridmethod as hybridmethod
1317
from ..util import hybridproperty as hybridproperty
@@ -25,10 +29,15 @@ class DeclarativeMeta(type):
2529

2630
def synonym_for(name: Any, map_column: bool = ...): ...
2731

28-
class declared_attr(interfaces._MappedAttribute, property):
32+
_T = TypeVar("_T")
33+
_Generic_T = Generic[_T]
34+
35+
class declared_attr(interfaces._MappedAttribute, property, Generic[_T]):
2936
__doc__: Any = ...
3037
def __init__(self, fget: Any, cascading: bool = ...) -> None: ...
31-
def __get__(desc: Any, self: Any, cls: Any): ...
38+
def __get__(
39+
desc: Any, self: Any, cls: Any
40+
) -> Union[interfaces.MapperProperty, ColumnElement]: ...
3241
def cascading(cls): ...
3342

3443
class _stateful_declared_attr(declared_attr):

sqlalchemy-stubs/orm/descriptor_props.pyi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any
22
from typing import Optional
3+
from typing import TypeVar
34

45
from . import attributes as attributes
56
from . import util as orm_util
@@ -11,14 +12,16 @@ from .. import sql as sql
1112
from .. import util as util
1213
from ..sql import expression as expression
1314

14-
class DescriptorProperty(MapperProperty):
15+
_T = TypeVar("_T")
16+
17+
class DescriptorProperty(MapperProperty[_T]):
1518
doc: Any = ...
1619
uses_objects: bool = ...
1720
key: Any = ...
1821
descriptor: Any = ...
1922
def instrument_class(self, mapper: Any): ...
2023

21-
class CompositeProperty(DescriptorProperty):
24+
class CompositeProperty(DescriptorProperty[_T]):
2225
attrs: Any = ...
2326
composite_class: Any = ...
2427
active_history: Any = ...
@@ -47,11 +50,11 @@ class CompositeProperty(DescriptorProperty):
4750
def __eq__(self, other: Any) -> Any: ...
4851
def __ne__(self, other: Any) -> Any: ...
4952

50-
class ConcreteInheritedProperty(DescriptorProperty):
53+
class ConcreteInheritedProperty(DescriptorProperty[_T]):
5154
descriptor: Any = ...
5255
def __init__(self): ...
5356

54-
class SynonymProperty(DescriptorProperty):
57+
class SynonymProperty(DescriptorProperty[_T]):
5558
name: Any = ...
5659
map_column: Any = ...
5760
descriptor: Any = ...

sqlalchemy-stubs/orm/interfaces.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import Any
2+
from typing import Generic
23
from typing import Optional
4+
from typing import TypeVar
35

46
from .base import _MappedAttribute
57
from .base import EXT_CONTINUE as EXT_CONTINUE
@@ -23,8 +25,14 @@ class ORMColumnsClauseRole(roles.ColumnsClauseRole): ...
2325
class ORMEntityColumnsClauseRole(ORMColumnsClauseRole): ...
2426
class ORMFromClauseRole(roles.StrictFromClauseRole): ...
2527

28+
_T = TypeVar("_T")
29+
2630
class MapperProperty(
27-
HasCacheKey, _MappedAttribute, InspectionAttr, util.MemoizedSlots
31+
HasCacheKey,
32+
_MappedAttribute,
33+
InspectionAttr,
34+
util.MemoizedSlots,
35+
Generic[_T],
2836
):
2937
cascade: Any = ...
3038
is_property: bool = ...
@@ -99,7 +107,7 @@ class PropComparator(operators.ColumnOperators):
99107
def any(self, criterion: Optional[Any] = ..., **kwargs: Any): ...
100108
def has(self, criterion: Optional[Any] = ..., **kwargs: Any): ...
101109

102-
class StrategizedProperty(MapperProperty):
110+
class StrategizedProperty(MapperProperty[_T]):
103111
inherit_cache: bool = ...
104112
strategy_wildcard_key: Any = ...
105113
def setup(

sqlalchemy-stubs/orm/relationships.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any
22
from typing import Optional
33
from typing import Type
4+
from typing import TypeVar
45
from typing import Union
56

67
from . import attributes as attributes
@@ -31,7 +32,9 @@ from ..sql.util import visit_binary_product as visit_binary_product
3132
def remote(expr: Any): ...
3233
def foreign(expr: Any): ...
3334

34-
class RelationshipProperty(StrategizedProperty):
35+
_T = TypeVar("_T")
36+
37+
class RelationshipProperty(StrategizedProperty[_T]):
3538
strategy_wildcard_key: str = ...
3639
inherit_cache: bool = ...
3740
uselist: Any = ...

sqlalchemy-stubs/sql/elements.pyi

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ from .. import exc as exc
2727
from .. import inspection as inspection
2828
from .. import util as util
2929

30-
_T = TypeVar("_T", bound=type_api.TypeEngine)
30+
_TE = TypeVar("_TE", bound=type_api.TypeEngine)
3131

3232
def collate(expression: Any, collation: Any): ...
3333
def between(
@@ -79,7 +79,7 @@ class ColumnElement(
7979
roles.DDLExpressionRole,
8080
operators.ColumnOperators,
8181
ClauseElement,
82-
Generic[_T],
82+
Generic[_TE],
8383
):
8484
__visit_name__: str = ...
8585
primary_key: bool = ...
@@ -107,7 +107,7 @@ class WrapsColumnExpression:
107107
@property
108108
def anon_label(self): ...
109109

110-
class BindParameter(roles.InElementRole, ColumnElement[_T]):
110+
class BindParameter(roles.InElementRole, ColumnElement[_TE]):
111111
__visit_name__: str = ...
112112
inherit_cache: bool = ...
113113
key: Any = ...
@@ -171,15 +171,15 @@ class TextClause(
171171
self, against: Optional[Any] = ...
172172
) -> Union[Grouping, TextClause]: ...
173173

174-
class Null(SingletonConstant, roles.ConstExprRole, ColumnElement[_T]):
174+
class Null(SingletonConstant, roles.ConstExprRole, ColumnElement[_TE]):
175175
__visit_name__: str = ...
176176
def type(self): ...
177177

178-
class False_(SingletonConstant, roles.ConstExprRole, ColumnElement[_T]):
178+
class False_(SingletonConstant, roles.ConstExprRole, ColumnElement[_TE]):
179179
__visit_name__: str = ...
180180
def type(self): ...
181181

182-
class True_(SingletonConstant, roles.ConstExprRole, ColumnElement[_T]):
182+
class True_(SingletonConstant, roles.ConstExprRole, ColumnElement[_TE]):
183183
__visit_name__: str = ...
184184
def type(self): ...
185185

@@ -201,7 +201,7 @@ class ClauseList(
201201
def append(self, clause: Any) -> None: ...
202202
def self_group(self, against: Optional[Any] = ...) -> ClauseElement: ...
203203

204-
class BooleanClauseList(ClauseList, ColumnElement[_T]):
204+
class BooleanClauseList(ClauseList, ColumnElement[_TE]):
205205
__visit_name__: str = ...
206206
inherit_cache: bool = ...
207207
def __init__(self, *arg: Any, **kw: Any) -> None: ...
@@ -214,13 +214,13 @@ class BooleanClauseList(ClauseList, ColumnElement[_T]):
214214
and_: Any
215215
or_: Any
216216

217-
class Tuple(ClauseList, ColumnElement[_T]):
217+
class Tuple(ClauseList, ColumnElement[_TE]):
218218
__visit_name__: str = ...
219219
type: Any = ...
220220
def __init__(self, *clauses: Any, **kw: Any) -> None: ...
221221
def self_group(self, against: Optional[Any] = ...): ...
222222

223-
class Case(ColumnElement[_T]):
223+
class Case(ColumnElement[_TE]):
224224
__visit_name__: str = ...
225225
value: Any = ...
226226
type: Any = ...
@@ -230,7 +230,7 @@ class Case(ColumnElement[_T]):
230230

231231
def literal_column(text: Any, type_: Optional[Any] = ...): ...
232232

233-
class Cast(WrapsColumnExpression, ColumnElement[_T]):
233+
class Cast(WrapsColumnExpression, ColumnElement[_TE]):
234234
__visit_name__: str = ...
235235
type: Any = ...
236236
clause: Any = ...
@@ -239,7 +239,7 @@ class Cast(WrapsColumnExpression, ColumnElement[_T]):
239239
@property
240240
def wrapped_column_expression(self): ...
241241

242-
class TypeCoerce(WrapsColumnExpression, ColumnElement[_T]):
242+
class TypeCoerce(WrapsColumnExpression, ColumnElement[_TE]):
243243
__visit_name__: str = ...
244244
type: Any = ...
245245
clause: Any = ...
@@ -249,24 +249,24 @@ class TypeCoerce(WrapsColumnExpression, ColumnElement[_T]):
249249
def wrapped_column_expression(self): ...
250250
def self_group(self, against: Optional[Any] = ...): ...
251251

252-
class Extract(ColumnElement[_T]):
252+
class Extract(ColumnElement[_TE]):
253253
__visit_name__: str = ...
254254
type: Any = ...
255255
field: Any = ...
256256
expr: Any = ...
257257
def __init__(self, field: Any, expr: Any, **kwargs: Any) -> None: ...
258258

259-
class _label_reference(ColumnElement[_T]):
259+
class _label_reference(ColumnElement[_TE]):
260260
__visit_name__: str = ...
261261
element: Any = ...
262262
def __init__(self, element: Any) -> None: ...
263263

264-
class _textual_label_reference(ColumnElement[_T]):
264+
class _textual_label_reference(ColumnElement[_TE]):
265265
__visit_name__: str = ...
266266
element: Any = ...
267267
def __init__(self, element: Any) -> None: ...
268268

269-
class UnaryExpression(ColumnElement[_T]):
269+
class UnaryExpression(ColumnElement[_TE]):
270270
__visit_name__: str = ...
271271
operator: Any = ...
272272
modifier: Any = ...
@@ -300,7 +300,7 @@ class AsBoolean(WrapsColumnExpression, UnaryExpression):
300300
def wrapped_column_expression(self): ...
301301
def self_group(self, against: Optional[Any] = ...) -> ClauseElement: ...
302302

303-
class BinaryExpression(ColumnElement[_T]):
303+
class BinaryExpression(ColumnElement[_TE]):
304304
__visit_name__: str = ...
305305
left: Any = ...
306306
right: Any = ...
@@ -323,7 +323,7 @@ class BinaryExpression(ColumnElement[_T]):
323323
def is_comparison(self): ...
324324
def self_group(self, against: Optional[Any] = ...) -> ClauseElement: ...
325325

326-
class Slice(ColumnElement[_T]):
326+
class Slice(ColumnElement[_TE]):
327327
__visit_name__: str = ...
328328
start: Any = ...
329329
stop: Any = ...
@@ -340,7 +340,7 @@ class GroupedElement(ClauseElement):
340340
__visit_name__: str = ...
341341
def self_group(self, against: Optional[Any] = ...) -> ClauseElement: ...
342342

343-
class Grouping(GroupedElement, ColumnElement[_T]):
343+
class Grouping(GroupedElement, ColumnElement[_TE]):
344344
element: Any = ...
345345
type: Any = ...
346346
def __init__(self, element: Any) -> None: ...
@@ -349,7 +349,7 @@ class Grouping(GroupedElement, ColumnElement[_T]):
349349
RANGE_UNBOUNDED: Any
350350
RANGE_CURRENT: Any
351351

352-
class Over(ColumnElement[_T]):
352+
class Over(ColumnElement[_TE]):
353353
__visit_name__: str = ...
354354
order_by: Any = ...
355355
partition_by: Any = ...
@@ -367,7 +367,7 @@ class Over(ColumnElement[_T]):
367367
def __reduce__(self): ...
368368
def type(self): ...
369369

370-
class WithinGroup(ColumnElement[_T]):
370+
class WithinGroup(ColumnElement[_TE]):
371371
__visit_name__: str = ...
372372
order_by: Any = ...
373373
element: Any = ...
@@ -381,7 +381,7 @@ class WithinGroup(ColumnElement[_T]):
381381
): ...
382382
def type(self): ...
383383

384-
class FunctionFilter(ColumnElement[_T]):
384+
class FunctionFilter(ColumnElement[_TE]):
385385
__visit_name__: str = ...
386386
criterion: Any = ...
387387
func: Any = ...
@@ -397,7 +397,7 @@ class FunctionFilter(ColumnElement[_T]):
397397
def self_group(self, against: Optional[Any] = ...): ...
398398
def type(self): ...
399399

400-
class Label(roles.LabeledColumnExprRole, ColumnElement[_T]):
400+
class Label(roles.LabeledColumnExprRole, ColumnElement[_TE]):
401401
__visit_name__: str = ...
402402
name: Any = ...
403403
key: Any = ...
@@ -413,7 +413,7 @@ class Label(roles.LabeledColumnExprRole, ColumnElement[_T]):
413413
@property
414414
def foreign_keys(self): ...
415415

416-
class NamedColumn(ColumnElement[_T]):
416+
class NamedColumn(ColumnElement[_TE]):
417417
is_literal: bool = ...
418418
table: Any = ...
419419
def description(self): ...
@@ -450,7 +450,7 @@ class TableValuedColumn(NamedColumn):
450450
type: Any = ...
451451
def __init__(self, scalar_alias: Any, type_: Any) -> None: ...
452452

453-
class CollationClause(ColumnElement[_T]):
453+
class CollationClause(ColumnElement[_TE]):
454454
__visit_name__: str = ...
455455
collation: Any = ...
456456
def __init__(self, collation: Any) -> None: ...

sqlalchemy-stubs/sql/schema.pyi

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import Any
22
from typing import Optional
3+
from typing import overload
4+
from typing import Type
35

46
from . import coercions as coercions
57
from . import ddl as ddl
@@ -26,7 +28,7 @@ RETAIN_SCHEMA: Any
2628
BLANK_SCHEMA: Any
2729
NULL_UNSPECIFIED: Any
2830

29-
_T = TypeVar("_T", bound=type_api.TypeEngine)
31+
_TE = TypeVar("_TE", bound=type_api.TypeEngine)
3032

3133
class SchemaItem(SchemaEventTarget, visitors.Visitable):
3234
__visit_name__: str = ...
@@ -72,7 +74,7 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
7274
name: Optional[Any] = ...,
7375
): ...
7476

75-
class Column(DialectKWArgs, SchemaItem, ColumnClause[_T]):
77+
class Column(DialectKWArgs, SchemaItem, ColumnClause[_TE]):
7678
__visit_name__: str = ...
7779
inherit_cache: bool = ...
7880
key: Any = ...
@@ -93,6 +95,18 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause[_T]):
9395
computed: Any = ...
9496
identity: Any = ...
9597
info: Any = ...
98+
@overload
99+
def __init__(
100+
self, name: str, typ: _TE, *args: Any, **kwargs: Any
101+
) -> None: ...
102+
@overload
103+
def __init__(self, typ: _TE, *args: Any, **kwargs: Any) -> None: ...
104+
@overload
105+
def __init__(
106+
self, name: str, typ: Type[_TE], *args: Any, **kwargs: Any
107+
) -> None: ...
108+
@overload
109+
def __init__(self, typ: Type[_TE], *args: Any, **kwargs: Any) -> None: ...
96110
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
97111
def references(self, column: Any): ...
98112
def append_foreign_key(self, fk: Any) -> None: ...

0 commit comments

Comments
 (0)