Skip to content

Commit 3015d30

Browse files
committed
propose new pep-484 no-pluguns declarative layer
References: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3074 Fixes: #170
1 parent 54b56f3 commit 3015d30

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed

sqlalchemy-stubs/orm/__init__.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from typing import Mapping
33
from typing import Optional
44
from typing import Tuple
55

6+
from . import decl_m as m # noqa
67
from . import exc as exc
78
from . import mapper as mapperlib # noqa
89
from . import strategy_options

sqlalchemy-stubs/orm/decl_m.pyi

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
from typing import AbstractSet
2+
from typing import Any
3+
from typing import Callable
4+
from typing import Literal
5+
from typing import Mapping
6+
from typing import MutableMapping
7+
from typing import Optional
8+
from typing import overload
9+
from typing import Sequence
10+
from typing import Tuple
11+
from typing import Type
12+
from typing import TypeVar
13+
from typing import Union
14+
15+
from sqlalchemy.sql.elements import ColumnElement
16+
from .attributes import Mapped as Mapped
17+
from .relationships import _OrderByArgument
18+
from ..sql import schema
19+
from ..sql import sqltypes
20+
from ..sql.schema import _ServerDefaultType
21+
from ..sql.schema import FetchedValue
22+
from ..sql.schema import SchemaEventTarget
23+
24+
_T = TypeVar("_T")
25+
26+
_BackrefResult = Tuple[str, Mapping[str, Any]]
27+
28+
class MappedColumn(Mapped[_T]):
29+
def __init__(self, expr: _T) -> None: ...
30+
def operate(self, op: Any, *other: Any, **kwargs: Any): ...
31+
def reverse_operate(self, op: Any, other: Any, **kwargs: Any): ...
32+
33+
@overload
34+
def column(
35+
__name: str,
36+
*args: SchemaEventTarget,
37+
autoincrement: Union[bool, Literal["auto", "ignore_fk"]] = ...,
38+
default: Optional[Any] = ...,
39+
doc: Optional[str] = ...,
40+
key: Optional[str] = ...,
41+
index: Optional[bool] = ...,
42+
info: MutableMapping[Any, Any] = ...,
43+
nullable: bool = ...,
44+
onupdate: Optional[Any] = ...,
45+
primary_key: bool = ...,
46+
server_default: Optional[_ServerDefaultType[Any]] = ...,
47+
server_onupdate: Optional[FetchedValue] = ...,
48+
quote: Optional[bool] = ...,
49+
unique: Optional[bool] = ...,
50+
system: bool = ...,
51+
comment: Optional[str] = ...,
52+
**kwargs: Any,
53+
) -> Mapped[Any]: ...
54+
@overload
55+
def column(
56+
*args: SchemaEventTarget,
57+
autoincrement: Union[bool, Literal["auto", "ignore_fk"]] = ...,
58+
default: Optional[Any] = ...,
59+
doc: Optional[str] = ...,
60+
key: Optional[str] = ...,
61+
index: Optional[bool] = ...,
62+
info: MutableMapping[Any, Any] = ...,
63+
nullable: bool = ...,
64+
onupdate: Optional[Any] = ...,
65+
primary_key: bool = ...,
66+
server_default: Optional[_ServerDefaultType[Any]] = ...,
67+
server_onupdate: Optional[FetchedValue] = ...,
68+
quote: Optional[bool] = ...,
69+
unique: Optional[bool] = ...,
70+
system: bool = ...,
71+
comment: Optional[str] = ...,
72+
**kwargs: Any,
73+
) -> Mapped[Any]: ...
74+
@overload
75+
def column(
76+
__name: str,
77+
_type: Union[sqltypes.TypeEngine[_T], Type[sqltypes.TypeEngine[_T]]],
78+
*args: SchemaEventTarget,
79+
autoincrement: Union[bool, Literal["auto", "ignore_fk"]] = ...,
80+
default: Optional[Any] = ...,
81+
doc: Optional[str] = ...,
82+
key: Optional[str] = ...,
83+
index: Optional[bool] = ...,
84+
info: MutableMapping[Any, Any] = ...,
85+
nullable: bool = ...,
86+
onupdate: Optional[Any] = ...,
87+
primary_key: bool = ...,
88+
server_default: Optional[_ServerDefaultType[schema._TE]] = ...,
89+
server_onupdate: Optional[FetchedValue] = ...,
90+
quote: Optional[bool] = ...,
91+
unique: Optional[bool] = ...,
92+
system: bool = ...,
93+
comment: Optional[str] = ...,
94+
**kwargs: Any,
95+
) -> Mapped[_T]: ...
96+
@overload
97+
def column(
98+
_type: Union[sqltypes.TypeEngine[_T], Type[sqltypes.TypeEngine[_T]]],
99+
*args: SchemaEventTarget,
100+
autoincrement: Union[bool, Literal["auto", "ignore_fk"]] = ...,
101+
default: Optional[Any] = ...,
102+
doc: Optional[str] = ...,
103+
key: Optional[str] = ...,
104+
index: Optional[bool] = ...,
105+
info: MutableMapping[Any, Any] = ...,
106+
nullable: bool = ...,
107+
onupdate: Optional[Any] = ...,
108+
primary_key: bool = ...,
109+
server_default: Optional[_ServerDefaultType[schema._TE]] = ...,
110+
server_onupdate: Optional[FetchedValue] = ...,
111+
quote: Optional[bool] = ...,
112+
unique: Optional[bool] = ...,
113+
system: bool = ...,
114+
comment: Optional[str] = ...,
115+
**kwargs: Any,
116+
) -> Mapped[_T]: ...
117+
def column_property(
118+
expr: ColumnElement[sqltypes.TypeEngine[_T]],
119+
*addl: ColumnElement[Any],
120+
**kw: Any,
121+
) -> Mapped[_T]: ...
122+
def composite(cls: _T, *arg: Any, **kw: Any) -> Mapped[_T]: ...
123+
def deferred(
124+
expr: ColumnElement[sqltypes.TypeEngine[_T]],
125+
*addl: ColumnElement[Any],
126+
**kw: Any,
127+
) -> Mapped[_T]: ...
128+
def query_expression(
129+
typ: sqltypes.TypeEngine[_T], default_expr: Any = ...
130+
) -> Mapped[_T]: ...
131+
def synonym(*arg, **kw) -> Any: ...
132+
def related(
133+
entity: Optional[_T] = ...,
134+
secondary: Optional[Any] = ...,
135+
primaryjoin: Optional[Any] = ...,
136+
secondaryjoin: Optional[Any] = ...,
137+
foreign_keys: Optional[Any] = ...,
138+
uselist: Optional[bool] = ...,
139+
order_by: _OrderByArgument = ...,
140+
backref: Union[str, _BackrefResult] = ...,
141+
back_populates: str = ...,
142+
overlaps: Union[AbstractSet[str], str] = ...,
143+
post_update: bool = ...,
144+
cascade: Union[Literal[False], Sequence[str]] = ...,
145+
viewonly: bool = ...,
146+
lazy: str = ...,
147+
collection_class: Optional[Union[Type[Any], Callable[[], Any]]] = ...,
148+
passive_deletes: Union[bool, Literal["all"]] = ...,
149+
passive_updates: bool = ...,
150+
remote_side: Optional[Any] = ...,
151+
enable_typechecks: bool = ..., # NOTE: not documented
152+
join_depth: Optional[int] = ...,
153+
comparator_factory: Optional[Any] = ...,
154+
single_parent: bool = ...,
155+
innerjoin: Union[bool, str] = ...,
156+
distinct_target_key: Optional[bool] = ...,
157+
doc: Optional[str] = ...,
158+
active_history: bool = ...,
159+
cascade_backrefs: bool = ...,
160+
load_on_pending: bool = ...,
161+
bake_queries: bool = ...,
162+
_local_remote_pairs: Optional[Any] = ...,
163+
query_class: Optional[Any] = ...,
164+
info: Optional[MutableMapping[Any, Any]] = ...,
165+
omit_join: Optional[Literal[False]] = ...,
166+
sync_backref: Optional[Any] = ...,
167+
) -> Mapped[_T]: ...
168+
def declared_attr(
169+
fget: Callable[[Any], Mapped[_T]], cascading: bool = ...
170+
) -> Mapped[_T]: ...

0 commit comments

Comments
 (0)