Repository navigation
Python: Fix: readable TypeError for union response_type mismatch (no __name__ crash on 3.10/3.11) - #9335
Open
PratikDhanave (PratikDhanave) wants to merge 1 commit into
Conversation
… crash)
send_request_info_response built the mismatch message with
event.response_type.__name__. response_type may legitimately be a union
(is_instance_of accepts type | UnionType | Any, and callers pass e.g.
int | str). On Python 3.10/3.11 types.UnionType has no __name__, so the
error path itself raised AttributeError instead of the intended TypeError;
on 3.12+ it only yields the unhelpful "Union".
Use response_type.__name__ for plain classes and str(response_type) for
unions/generics, so the message names the actual type ("int | str",
"list[int]") on every supported Python version.
Add a regression test (response_type=int | str, mismatched response)
asserting the message names the union.
PratikDhanave (PratikDhanave)
requested review from
SergeyMenshykh,
Tao Chen (TaoChenOSU),
Eduard van Valkenburg (eavanvalkenburg),
Giles Odigwe (giles17),
Jose Alvarez (jpalvarezl),
Evan Mattson (moonbox3),
Roger Barreto (rogerbarreto),
sophia-ramsey and
westey (westey-m)
as code owners
October 13, 2026 12:49
PratikDhanave (PratikDhanave)
deployed
to
github-app-auth
October 13, 2026 12:49 — with
GitHub Actions
Active
PratikDhanave (PratikDhanave)
deployed
to
github-app-auth
October 13, 2026 12:49 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new union argument conflicts with the typed request-info API and will fail test type-checking.
1 open finding
What changed in this PR
Improves workflow response mismatch errors for union and generic response types.
Changes:
- Adds defensive expected-type formatting.
- Adds a union mismatch regression test.
| File | Description |
|---|---|
_runner_context.py |
Formats non-class response types readably. |
test_request_info_event_rehydrate.py |
Tests union mismatch errors. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| request_id="union-req", | ||
| source_executor_id="gateway", | ||
| request_data=MockRequest(), | ||
| response_type=int | str, |
This branch was successfully deployed
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.

Motivation & Context
InProcRunnerContext.send_request_info_responsevalidates the response against the request'sresponse_typeand, on mismatch, raisesTypeErrorwith a message built fromevent.response_type.__name__.response_typeis not restricted to plain classes —is_instance_of(data, target_type: type | UnionType | Any)explicitly accepts unions, and callers pass them (e.g.response_type=int | str).types.UnionTypehas no__name__on Python 3.10/3.11 (it was only added in 3.12, gh-105499). Since the package declaresrequires-python = ">=3.10", on those interpreters the error path itself raisesAttributeError— masking the intendedTypeErrorwith a confusing, unrelated exception. On 3.12+ it doesn't crash but yields the unhelpful"expected Union".Description & Review Guide
Compute the display name defensively: use
__name__for real classes, andstr(...)for anything else (unions, generics):int | str,list[int], as well as plainint. No API/signature change.response_type=int | strand a mismatched (float) response, asserting the message readsexpected int | str, got float. On 3.10/3.11 the old code raisedAttributeError(noTypeErrorat all); on 3.12+ it producedexpected Union. Fails before, passes after. Fulltest_request_info_event_rehydrate.pysuite green (11 passed).Related Issue
N/A - trivial change: a localized hardening of one error-message expression, covered by a new unit test.
AI Assistance
AI assistance details: This change was developed with Claude Code (an AI agent) — it located the bug, wrote the fix and the regression test, and ran verification (pytest). PratikDhanave (@PratikDhanave) to review and tick the AI-assisted attestation above before merge.
Contribution Checklist