Skip to content

Commit dc3acf2

Browse files
authored
Merge pull request #15 from layday/improve-registry-annotations
Improve declarative API annotations
2 parents a0e1ae4 + 791482e commit dc3acf2

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

sqlalchemy-stubs/orm/decl_api.pyi

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from typing import Any
2+
from typing import Callable
3+
from typing import FrozenSet
24
from typing import Generic
5+
from typing import MutableMapping
36
from typing import Optional
7+
from typing import Tuple
8+
from typing import Type
49
from typing import TypeVar
510
from typing import Union
611

@@ -12,11 +17,14 @@ from .mapper import Mapper as Mapper
1217
from .. import inspection as inspection
1318
from .. import util as util
1419
from ..sql import ColumnElement
20+
from ..sql import FromClause
1521
from ..sql.schema import MetaData as MetaData
1622
from ..util import hybridmethod as hybridmethod
1723
from ..util import hybridproperty as hybridproperty
1824

19-
def has_inherited_table(cls): ...
25+
_T = TypeVar("_T")
26+
27+
def has_inherited_table(cls: type) -> bool: ...
2028

2129
class DeclarativeMeta(type):
2230
def __init__(
@@ -25,13 +33,10 @@ class DeclarativeMeta(type):
2533
def __setattr__(cls, key: Any, value: Any) -> None: ...
2634
def __delattr__(cls, key: Any) -> None: ...
2735
metadata: MetaData
28-
registry: "registry"
36+
registry: _registry # Avoid circural reference
2937

3038
def synonym_for(name: Any, map_column: bool = ...): ...
3139

32-
_T = TypeVar("_T")
33-
_Generic_T = Generic[_T]
34-
3540
class declared_attr(interfaces._MappedAttribute, property, Generic[_T]):
3641
__doc__: Any = ...
3742
def __init__(self, fget: Any, cascading: bool = ...) -> None: ...
@@ -46,42 +51,51 @@ class _stateful_declared_attr(declared_attr):
4651
def __call__(self, fn: Any): ...
4752

4853
def declarative_base(
49-
bind: Optional[Any] = ...,
50-
metadata: Optional[Any] = ...,
51-
mapper: Optional[Any] = ...,
52-
cls: Any = ...,
54+
bind: Optional[
55+
Any
56+
] = ..., # NOTE: Deprecated in 1.4, to be removed in 2.0.
57+
metadata: Optional[MetaData] = ...,
58+
mapper: Optional[Callable[..., Mapper]] = ...,
59+
cls: Union[type, Tuple[type, ...]] = ...,
5360
name: str = ...,
54-
constructor: Any = ...,
55-
class_registry: Optional[Any] = ...,
56-
metaclass: Any = ...,
57-
): ...
61+
constructor: Callable[..., None] = ...,
62+
class_registry: Optional[MutableMapping[Any, Any]] = ...,
63+
metaclass: type = ...,
64+
) -> type: ...
5865

5966
class registry:
60-
metadata: Any = ...
61-
constructor: Any = ...
67+
metadata: MetaData
68+
constructor: Callable[..., None]
6269
def __init__(
6370
self,
64-
metadata: Optional[Any] = ...,
65-
class_registry: Optional[Any] = ...,
66-
constructor: Any = ...,
71+
metadata: Optional[MetaData] = ...,
72+
class_registry: Optional[MutableMapping[Any, Any]] = ...,
73+
constructor: Callable[..., None] = ...,
6774
_bind: Optional[Any] = ...,
6875
) -> None: ...
6976
@property
70-
def mappers(self): ...
77+
def mappers(self) -> FrozenSet[Mapper]: ...
7178
def configure(self, cascade: bool = ...) -> None: ...
7279
def dispose(self, cascade: bool = ...) -> None: ...
7380
def generate_base(
7481
self,
75-
mapper: Optional[Any] = ...,
76-
cls: Any = ...,
82+
mapper: Optional[Callable[..., Mapper]] = ...,
83+
cls: Union[type, Tuple[type, ...]] = ...,
7784
name: str = ...,
78-
metaclass: Any = ...,
79-
): ...
80-
def mapped(self, cls: Any): ...
81-
def as_declarative_base(self, **kw: Any): ...
85+
metaclass: type = ...,
86+
) -> type: ...
87+
def mapped(self, cls: Type[_T]) -> Type[_T]: ...
88+
def as_declarative_base(
89+
self, **kw: Any
90+
) -> Callable[[Type[_T]], Type[_T]]: ...
8291
def map_declaratively(self, cls: type) -> Mapper: ...
8392
def map_imperatively(
84-
self, class_: Any, local_table: Optional[Any] = ..., **kw: Any
85-
): ...
93+
self,
94+
class_: type,
95+
local_table: Optional[FromClause] = ...,
96+
**kw: Any,
97+
) -> Mapper: ...
98+
99+
_registry = registry
86100

87-
def as_declarative(**kw: Any): ...
101+
def as_declarative(**kw: Any) -> Callable[[Type[_T]], Type[_T]]: ...

0 commit comments

Comments
 (0)