chore: add type hints to FastAPI SSE generator functions#5266
chore: add type hints to FastAPI SSE generator functions#5266Elbehery wants to merge 1 commit intollamastack:mainfrom
Conversation
fb92f59 to
f4394c4
Compare
cdoern
left a comment
There was a problem hiding this comment.
is there a way for this testing (rather than by hand) to be done by mypy going forward?
I can add tests for this, historically I was just running the cmd :D |
I added #5269 we can update the files section as we progress |
leseb
left a comment
There was a problem hiding this comment.
remove the pyproject.toml entry of the file you're fixing
removing the ignore entry from pyproject is how we validate this with CI EDIT: nevermind, was thinkig static type checking |
This change adds complete type annotations to sse_generator and _preserve_context_for_sse functions in agents/fastapi_routes.py to satisfy mypy's --disallow-untyped-defs requirement. These functions handle Server-Sent Events streaming for the Agents API responses. The sse_generator function converts async iterators to SSE format, while _preserve_context_for_sse preserves request context across async tasks for streaming responses. Type hints use AsyncIterator to properly type the async generator functions. A type ignore comment is used for the contextvars.Context.run pattern where the type system has limitations in expressing the dynamic task creation. All changes pass mypy strict checking and maintain full backward compatibility. Signed-off-by: Mustafa Elbehery <melbeher@redhat.com>
5f80415 to
eb7c144
Compare
|
This pull request has merge conflicts that must be resolved before it can be merged. @Elbehery please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork |
What does this PR do?
This change adds complete type annotations to sse_generator and
_preserve_context_for_sse functions in agents/fastapi_routes.py to satisfy
mypy's --disallow-untyped-defs requirement. These functions handle
Server-Sent Events streaming for the Agents API responses.
The sse_generator function converts async iterators to SSE format, while
_preserve_context_for_sse preserves request context across async tasks for
streaming responses. Type hints use AsyncIterator to properly type the
async generator functions.
A type ignore comment is used for the contextvars.Context.run pattern where
the type system has limitations in expressing the dynamic task creation. All
changes pass mypy strict checking and maintain full backward compatibility.
Test Plan