File tree Expand file tree Collapse file tree 3 files changed +33
-8
lines changed Expand file tree Collapse file tree 3 files changed +33
-8
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ from typing import Mapping
8
8
from typing import Optional
9
9
from typing import Protocol
10
10
from typing import Sequence
11
+ from typing import Type
11
12
from typing import TypeVar
12
13
from typing import Union
13
14
@@ -105,15 +106,15 @@ class _AsyncSessionProtocol(
105
106
) -> None : ...
106
107
async def get (
107
108
self ,
108
- entity : Any ,
109
+ entity : Type [ _T ] ,
109
110
ident : Any ,
110
111
options : Optional [Sequence [Any ]] = ...,
111
112
populate_existing : bool = ...,
112
113
with_for_update : Optional [
113
114
Union [Literal [True ], Mapping [str , Any ]]
114
115
] = ...,
115
116
identity_token : Optional [Any ] = ...,
116
- ) -> Any : ...
117
+ ) -> Optional [ _T ] : ...
117
118
async def stream (
118
119
self ,
119
120
statement : Any ,
@@ -155,13 +156,13 @@ class _AsyncSessionTypingCommon(
155
156
async def flush (self , objects : Optional [Any ] = ...) -> None : ...
156
157
async def get (
157
158
self ,
158
- entity : Any ,
159
+ entity : Type [ _T ] ,
159
160
ident : Any ,
160
161
options : Optional [Any ] = ...,
161
162
populate_existing : bool = ...,
162
163
with_for_update : Optional [Any ] = ...,
163
164
identity_token : Optional [Any ] = ...,
164
- ) -> Any : ...
165
+ ) -> Optional [ _T ] : ...
165
166
async def merge (self , instance : _T , load : bool = ...) -> _T : ...
166
167
async def refresh (
167
168
self ,
Original file line number Diff line number Diff line change @@ -144,15 +144,15 @@ class _SessionProtocol(
144
144
def delete (self , instance : Any ) -> None : ...
145
145
def get (
146
146
self ,
147
- entity : Any ,
147
+ entity : Type [ _T ] ,
148
148
ident : Any ,
149
149
options : Optional [Sequence [Any ]] = ...,
150
150
populate_existing : bool = ...,
151
151
with_for_update : Optional [
152
152
Union [Literal [True ], Mapping [str , Any ]]
153
153
] = ...,
154
154
identity_token : Optional [Any ] = ...,
155
- ) -> Any : ...
155
+ ) -> Optional [ _T ] : ...
156
156
def merge (self , instance : _T , load : bool = ...) -> _T : ...
157
157
def flush (self , objects : Optional [Collection [Any ]] = ...) -> None : ...
158
158
@classmethod
@@ -364,15 +364,15 @@ class _SessionTypingCommon(_SessionNoIoTypingCommon):
364
364
def flush (self , objects : Optional [Collection [Any ]] = ...) -> None : ...
365
365
def get (
366
366
self ,
367
- entity : Any ,
367
+ entity : Type [ _T ] ,
368
368
ident : Any ,
369
369
options : Optional [Sequence [Any ]] = ...,
370
370
populate_existing : bool = ...,
371
371
with_for_update : Optional [
372
372
Union [Literal [True ], Mapping [str , Any ]]
373
373
] = ...,
374
374
identity_token : Optional [Any ] = ...,
375
- ) -> Any : ...
375
+ ) -> Optional [ _T ] : ...
376
376
def bulk_save_objects (
377
377
self ,
378
378
objects : Sequence [Any ],
Original file line number Diff line number Diff line change
1
+ from typing import Optional
2
+
3
+ from sqlalchemy import Column
4
+ from sqlalchemy import Integer
5
+ from sqlalchemy .ext .asyncio import AsyncSession
6
+ from sqlalchemy .orm import registry
7
+ from sqlalchemy .orm import Session
8
+
9
+ mr : registry = registry ()
10
+
11
+
12
+ @mr .mapped
13
+ class Foo :
14
+ id = Column (Integer , primary_key = True )
15
+ __tablename__ = "foo"
16
+
17
+
18
+ s = Session ()
19
+ x : Optional [Foo ] = s .get (Foo , 1 )
20
+
21
+
22
+ async def go () -> None :
23
+ as_ = AsyncSession ()
24
+ y : Optional [Foo ] = await as_ .get (Foo , 1 )
You can’t perform that action at this time.
0 commit comments