88import logging # noqa: F401
99import re
1010from collections .abc import AsyncIterator , Sequence
11- from typing import TYPE_CHECKING , Any , Literal , TypedDict
11+ from typing import TYPE_CHECKING , Any , Literal , NoReturn , TypedDict
1212
1313if TYPE_CHECKING :
1414 from typing_extensions import Self
@@ -149,8 +149,11 @@ async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
149149 """Close the client when exiting the context manager."""
150150 await self .close ()
151151
152- def _handle_http_error (self , response : httpx .Response ) -> None :
153- """Handle HTTP errors and convert to appropriate exceptions."""
152+ def _handle_http_error (self , response : httpx .Response ) -> NoReturn :
153+ """Handle HTTP errors and convert to appropriate exceptions.
154+
155+ This method always raises an exception and never returns normally.
156+ """
154157 if response .status_code == 404 :
155158 from .exceptions import MemoryNotFoundError
156159
@@ -162,6 +165,10 @@ def _handle_http_error(self, response: httpx.Response) -> None:
162165 except Exception :
163166 message = f"HTTP { response .status_code } : { response .text } "
164167 raise MemoryServerError (message , response .status_code )
168+ # This should never be reached, but mypy needs to know this never returns
169+ raise MemoryServerError (
170+ f"Unexpected status code: { response .status_code } " , response .status_code
171+ )
165172
166173 async def health_check (self ) -> HealthCheckResponse :
167174 """
@@ -176,7 +183,6 @@ async def health_check(self) -> HealthCheckResponse:
176183 return HealthCheckResponse (** response .json ())
177184 except httpx .HTTPStatusError as e :
178185 self ._handle_http_error (e .response )
179- raise
180186
181187 async def list_sessions (
182188 self ,
@@ -215,7 +221,6 @@ async def list_sessions(
215221 return SessionListResponse (** response .json ())
216222 except httpx .HTTPStatusError as e :
217223 self ._handle_http_error (e .response )
218- raise
219224
220225 async def get_working_memory (
221226 self ,
@@ -291,7 +296,6 @@ async def get_working_memory(
291296 return WorkingMemoryResponse (** response_data )
292297 except httpx .HTTPStatusError as e :
293298 self ._handle_http_error (e .response )
294- raise
295299
296300 async def get_or_create_working_memory (
297301 self ,
@@ -454,7 +458,6 @@ async def put_working_memory(
454458 return WorkingMemoryResponse (** response .json ())
455459 except httpx .HTTPStatusError as e :
456460 self ._handle_http_error (e .response )
457- raise
458461
459462 async def delete_working_memory (
460463 self , session_id : str , namespace : str | None = None , user_id : str | None = None
@@ -487,7 +490,6 @@ async def delete_working_memory(
487490 return AckResponse (** response .json ())
488491 except httpx .HTTPStatusError as e :
489492 self ._handle_http_error (e .response )
490- raise
491493
492494 async def set_working_memory_data (
493495 self ,
@@ -678,7 +680,6 @@ async def create_long_term_memory(
678680 return AckResponse (** response .json ())
679681 except httpx .HTTPStatusError as e :
680682 self ._handle_http_error (e .response )
681- raise
682683
683684 async def delete_long_term_memories (self , memory_ids : Sequence [str ]) -> AckResponse :
684685 """
@@ -701,7 +702,6 @@ async def delete_long_term_memories(self, memory_ids: Sequence[str]) -> AckRespo
701702 return AckResponse (** response .json ())
702703 except httpx .HTTPStatusError as e :
703704 self ._handle_http_error (e .response )
704- raise
705705
706706 async def get_long_term_memory (self , memory_id : str ) -> MemoryRecord :
707707 """
@@ -722,7 +722,6 @@ async def get_long_term_memory(self, memory_id: str) -> MemoryRecord:
722722 return MemoryRecord (** response .json ())
723723 except httpx .HTTPStatusError as e :
724724 self ._handle_http_error (e .response )
725- raise
726725
727726 async def edit_long_term_memory (
728727 self , memory_id : str , updates : dict [str , Any ]
@@ -749,7 +748,6 @@ async def edit_long_term_memory(
749748 return MemoryRecord (** response .json ())
750749 except httpx .HTTPStatusError as e :
751750 self ._handle_http_error (e .response )
752- raise
753751
754752 async def search_long_term_memory (
755753 self ,
@@ -900,7 +898,6 @@ async def search_long_term_memory(
900898 return MemoryRecordResults (** data )
901899 except httpx .HTTPStatusError as e :
902900 self ._handle_http_error (e .response )
903- raise
904901
905902 # === LLM Tool Integration ===
906903
@@ -2957,7 +2954,6 @@ async def memory_prompt(
29572954 return {"response" : result }
29582955 except httpx .HTTPStatusError as e :
29592956 self ._handle_http_error (e .response )
2960- raise
29612957
29622958 async def hydrate_memory_prompt (
29632959 self ,
0 commit comments