Python: handle Literal annotations in is_instance_of - #8351
Open
Manohar Paturi (ManoharPaturi) wants to merge 4 commits into
Open
Manohar Paturi (ManoharPaturi) wants to merge 4 commits into
Manohar Paturi (ManoharPaturi) wants to merge 4 commits into
Conversation
…tance_of Executor handlers annotated with a Literal message type (e.g. `message: Literal["yes", "no"]`) pass @handler registration, executor construction, and WorkflowBuilder type validation, but crashed at message-delivery time with: TypeError: typing.Literal cannot be used with isinstance() is_instance_of() had no case for Literal origins and fell through to isinstance(data, Literal), which always raises. Executor.can_handle() and Executor._find_handler() call is_instance_of() directly, so any workflow containing such an executor failed on the first delivery. Add a Literal case that matches by allowed values with strict member types (bool never matches an int member), mirroring the existing _matches_annotation() semantics used by try_coerce_to_type.
Manohar Paturi (ManoharPaturi)
deployed
to
github-app-auth
September 13, 2026 16:48 — with
GitHub Actions
Active
Manohar Paturi (ManoharPaturi)
deployed
to
github-app-auth
September 13, 2026 16:48 — with
GitHub Actions
Active
Manohar Paturi (ManoharPaturi)
deployed
to
github-app-auth
September 13, 2026 16:49 — with
GitHub Actions
Active
Manohar Paturi (ManoharPaturi)
deployed
to
github-app-auth
September 13, 2026 16:49 — with
GitHub Actions
Active
Manohar Paturi (ManoharPaturi)
deployed
to
github-app-auth
September 14, 2026 05:20 — with
GitHub Actions
Active
…hes_annotation to is_instance_of - Reorder Literal evaluation to check type(data) is type(member) before data == member to prevent __eq__ side effects on mismatched types - Remove duplicate Literal check in _matches_annotation to delegate directly to is_instance_of - Add test verifying mismatched type with throwing __eq__ returns False without raising
Manohar Paturi (ManoharPaturi)
deployed
to
github-app-auth
September 14, 2026 05:25 — with
GitHub Actions
Active
Manohar Paturi (ManoharPaturi)
deployed
to
github-app-auth
September 14, 2026 05:47 — with
GitHub Actions
Active
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Sep 14, 2026
Eduard van Valkenburg (eavanvalkenburg)
left a comment
Member
There was a problem hiding this comment.
Looks good—thanks!
Eduard van Valkenburg (eavanvalkenburg)
deployed
to
github-app-auth
September 14, 2026 13:29 — with
GitHub Actions
Active
Eduard van Valkenburg (eavanvalkenburg)
enabled auto-merge
September 14, 2026 13:29
Manohar Paturi (ManoharPaturi)
deployed
to
github-app-auth
September 14, 2026 15:37 — with
GitHub Actions
Active
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
Workflows with a
Literalmessage annotation on a handler crash at the first message delivery:Executor.can_handle()/_find_handler()callis_instance_of()directly on the annotation, which has noLiteralcase and raisesTypeError: typing.Literal cannot be used with isinstance(). Registration and the builder type validation both acceptLiteral, and the sibling helper_matches_annotation()already implements the intended semantics, so the two validators disagree. Reported in #8350.Description & Review Guide
Literalcase tois_instance_of()that matches by allowed values with strict member types, aligned with_matches_annotation(), so registration, validation, and delivery agree onLiteralannotations.Literal-annotated handlers work end to end; no change for any other annotation type.Literal[0, 1]-style annotations) and the three new tests.Related Issue
Fixes #8350
Contribution Checklist