Enter the async context manager.
(self)
| 240 | ) |
| 241 | |
| 242 | async def __aenter__(self) -> Client: |
| 243 | """Enter the async context manager.""" |
| 244 | if self._entered: |
| 245 | raise RuntimeError("Client is already entered; cannot reenter") |
| 246 | self._entered = True |
| 247 | |
| 248 | async with AsyncExitStack() as exit_stack: |
| 249 | session = await self._build_session(exit_stack) |
| 250 | session = await exit_stack.enter_async_context(session) |
| 251 | |
| 252 | if self.mode == "legacy": |
| 253 | await session.initialize() |
| 254 | elif self.mode == "auto": |
| 255 | await negotiate_auto(session) |
| 256 | else: |
| 257 | session.adopt(self.prior_discover or _synthesize_discover(self.mode)) |
| 258 | |
| 259 | # Only publish the session after the handshake succeeds, so `_session is not None` |
| 260 | # implies the protocol_version/server_info/server_capabilities are populated. If the |
| 261 | # handshake raised above, the local exit_stack unwinds the transport for us. |
| 262 | self._session = session |
| 263 | self._exit_stack = exit_stack.pop_all() |
| 264 | return self |
| 265 | |
| 266 | async def __aexit__(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: Any) -> None: |
| 267 | """Exit the async context manager.""" |
nothing calls this directly
no test coverage detected