refactor(api): type _error_to_stream_response with ErrorStreamResponseDict TypedDict#34982
Open
aviu16 wants to merge 1 commit intolanggenius:mainfrom
Open
refactor(api): type _error_to_stream_response with ErrorStreamResponseDict TypedDict#34982aviu16 wants to merge 1 commit intolanggenius:mainfrom
aviu16 wants to merge 1 commit intolanggenius:mainfrom
Conversation
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-12 03:37:02.855638893 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-12 03:36:54.467662901 +0000
@@ -14,6 +14,20 @@
--> controllers/console/setup.py:65:2
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/version.py:30:2
+ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (ErrorStreamResponseDict) [no-matching-overload]
+ --> core/app/apps/agent_chat/generate_response_converter.py:82:38
+ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (ErrorStreamResponseDict) [no-matching-overload]
+ --> core/app/apps/agent_chat/generate_response_converter.py:118:38
+ERROR `dict[str, Any]` is not assignable to variable `data` with type `ErrorStreamResponseDict | None` [bad-assignment]
+ --> core/app/apps/base_app_generate_response_converter.py:139:24
+ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (ErrorStreamResponseDict) [no-matching-overload]
+ --> core/app/apps/chat/generate_response_converter.py:82:38
+ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (ErrorStreamResponseDict) [no-matching-overload]
+ --> core/app/apps/chat/generate_response_converter.py:118:38
+ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (ErrorStreamResponseDict) [no-matching-overload]
+ --> core/app/apps/completion/generate_response_converter.py:80:38
+ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (ErrorStreamResponseDict) [no-matching-overload]
+ --> core/app/apps/completion/generate_response_converter.py:117:38
ERROR Class member `EasyUIBasedGenerateTaskPipeline._application_generate_entity` overrides parent class `BasedGenerateTaskPipeline` in an inconsistent manner [bad-override]
--> core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py:75:5
ERROR `+=` is not supported between `list[PromptMessageContentUnionTypes]` and `str` [unsupported-operation]
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors _error_to_stream_response in the API app response conversion layer to make its return type explicit via a dedicated TypedDict, improving type safety for downstream stream response serialization/callers.
Changes:
- Introduces
ErrorStreamResponseDictTypedDictto describe the error stream payload shape. - Updates
_error_to_stream_responsereturn type (and a local variable) fromdict[str, Any]toErrorStreamResponseDict.
Comments suppressed due to low confidence (1)
api/core/app/apps/base_app_generate_response_converter.py:140
datais annotated asErrorStreamResponseDict, buterror_responsesvalues are plaindict[str, Any]and several entries omit the requiredmessagekey. With basedpyright, assigningvtodataand later mutating it viasetdefaultwill not type-check against a totalTypedDict. Consider typingerror_responseswith a (partial) TypedDict (e.g.,messageasNotRequired) and constructing a newErrorStreamResponseDictthat always includescode,status, and a computedmessagebefore returning (instead ofsetdefault).
data: ErrorStreamResponseDict | None = None
for k, v in error_responses.items():
if isinstance(e, k):
data = v
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #32863 (
api/core/app/apps/base_app_generate_response_converter.py)Summary
ErrorStreamResponseDictTypedDict for the_error_to_stream_responsereturn typedict[str, Any]return annotation anddatavariable annotation with the new TypedDictWhy this change
_error_to_stream_responsereturns a fixed 3-key dict (code,message,status) for every code path. The baredict[str, Any]hides this contract from the stream response serializer and callers in the chat/completion pipelines.Changes
api/core/app/apps/base_app_generate_response_converter.py: DefineErrorStreamResponseDict, annotate_error_to_stream_responsereturn type anddatalocal variable