|
182 | 182 |
|
183 | 183 | _IS_SYNC = False |
184 | 184 |
|
185 | | -_SESSION: ContextVar[Optional[_AsyncBoundClientSession]] = ContextVar("SESSION", default=None) |
| 185 | +_SESSION: ContextVar[Optional[AsyncClientSession]] = ContextVar("SESSION", default=None) |
186 | 186 |
|
187 | 187 |
|
188 | | -class _AsyncBoundClientSession: |
189 | | - def __init__(self, session: AsyncClientSession, client_id: int): |
190 | | - self.session = session |
191 | | - self.client_id = client_id |
192 | | - |
193 | | - |
194 | | -class AsyncBoundSessionContext: |
| 188 | +class _AsyncBoundSessionContext: |
195 | 189 | """Context manager returned by AsyncClientSession.bind() that manages bound state.""" |
196 | 190 |
|
197 | 191 | def __init__(self, session: AsyncClientSession) -> None: |
198 | 192 | self._session = session |
199 | | - self._session_token: Optional[Token[_AsyncBoundClientSession]] = None |
| 193 | + self._session_token: Optional[Token[AsyncClientSession]] = None |
200 | 194 |
|
201 | 195 | async def __aenter__(self) -> AsyncClientSession: |
202 | | - bound_session = _AsyncBoundClientSession(self._session, id(self._session._client)) |
203 | | - self._session_token = _SESSION.set(bound_session) # type: ignore[assignment] |
| 196 | + self._session_token = _SESSION.set(self._session) # type: ignore[assignment] |
204 | 197 | return self._session |
205 | 198 |
|
206 | 199 | async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: |
@@ -574,12 +567,12 @@ def _check_ended(self) -> None: |
574 | 567 | if self._server_session is None: |
575 | 568 | raise InvalidOperation("Cannot use ended session") |
576 | 569 |
|
577 | | - def bind(self) -> AsyncBoundSessionContext: |
| 570 | + def bind(self) -> _AsyncBoundSessionContext: |
578 | 571 | """Bind this session so it is implicitly passed to all database operations within the returned context. |
579 | 572 |
|
580 | 573 | .. versionadded:: 4.17 |
581 | 574 | """ |
582 | | - return AsyncBoundSessionContext(self) |
| 575 | + return _AsyncBoundSessionContext(self) |
583 | 576 |
|
584 | 577 | async def __aenter__(self) -> AsyncClientSession: |
585 | 578 | return self |
|
0 commit comments