Repository navigation
fix: let Pipeline.connect accept a Literal output for an input of its value type - #13642
Conversation
… value type Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@aryamangodara is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
lxcxjxhx
left a comment
There was a problem hiding this comment.
The new branch is right, and it is right for a reason worth naming: it compares type(value), not value.
return all(_strict_types_are_compatible(type(value), receiver) for value in sender_args)That matters for Literal[True] and Literal[1]. Python says True == 1 and True in (1,), so a membership test cannot tell them apart — but type(True) is bool and type(1) is int can, and bool/int then go through the existing issubclass path. If the branch had been written as all(value in receiver_args ...) or by comparing values directly, Literal[True] would have been accepted for an int input that cannot actually take a bool safely in the other direction.
One inconsistency this leaves behind, which I am flagging rather than asking you to fix here. A few lines down, the Literal-vs-Literal case still uses membership:
if sender_origin is receiver_origin is Literal:
return all(value in receiver_args for value in sender_args)So Literal[True] → Literal[1] passes that branch (True in (1,)), while your new branch would reject it. The two now disagree about the same pair of types depending on whether the receiver is a Literal. That is pre-existing, not something this PR introduces — but since this PR is exactly about how a Literal relates to a non-Literal, it is the natural place to note it.
If you want them consistent, the Literal-vs-Literal branch could compare (type(v), v) pairs instead of bare values. If you would rather keep this PR narrow, a comment on the membership line saying "values compare by equality, so True matches Literal[1]" would at least record the decision.
The Union recursion is also sound: _strict_types_are_compatible(Literal[value], union_arg) re-enters this same branch when union_arg is a plain type, and the inner call gets type(value), which is no longer a Literal — so it terminates.
|
Thanks for the review, @lxcxjxhx! Agreed: the |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Thanks! Can you also add a test for Literal["a"] can now feed list[str] ? |
DevNeto07
left a comment
There was a problem hiding this comment.
Reviewed fbc958d against its main merge parent bbf5b2b.
Following the maintainer's question about Literal["a"] feeding list[str], I exercised a real two-component Pipeline with that connection:
- Pipeline.run({}) and Pipeline.run_async({}) both deliver ["a"] to the list[str] consumer.
- The scalar Literal["a"] to list[list[str]] connection remains rejected.
This uses the existing WRAP conversion: the new strict Literal-to-str compatibility enables the list receiver through _get_conversion_strategy, rather than treating the scalar as already being a list. A regression for the connection's runtime output in both execution modes would pin that distinction.
The two existing type-utils and pipeline-base unit modules passed with 1,294 tests and 2 integration tests deselected. Commands were run through a separate Hatch environment with the project core dependencies and focused test dependencies. External-provider, document-converter integrations, and the full project suite were outside this validation.
No introduced correctness defect found in the reviewed diff.
Review assisted by Codex and Claude Code.
|
@DevNeto07 please don't post unsolicited automated reviews on PRs in this repo. Reviews like this just add noise by repeating what's already in the thread. If you'd like to contribute, the most helpful thing is see open issues. Also, note that if automated agent reviews like this keep appearing, we'll block the account from the repository. |
|
Understood. I apologize for the unsolicited automated reviews, including the later review posted after your warning. I will respect your request and will not post further unsolicited automated reviews in this repository. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks! Added it: |
Related Issues
Proposed Changes:
Pipeline.connect()rejected aLiteraloutput whenever the receiver wasn't itself aLiteral, even though every value the sender can produce is valid for the receiver:Cause:
_strict_types_are_compatibleonly handledLiteral→Literal(by membership). For any other receiver, the sender's origin (Literal) differed from the receiver's (str), so the check returnedFalse.Literal["a"] -> str | None,Literal[None] -> str | None,Literal[Enum.X] -> EnumandLiteral["a"] -> list[str](wrap) all failed the same way.Fix: a
Literalsender is now treated as the set of its values. Each value has to fit the receiver:type(value)checked against the receiver with the existing strict rules), orUnion, by being a member of one of itsLiteralarguments or matching one of its other arguments. That way mixed cases likeLiteral["a", 1] -> Literal["a"] | intwork, andLiteral["a", "x"] -> Literal["a"] | intis still rejected.Literal -> Literalkeeps its membership rule, the reverse direction (str -> Literal[...]) stays incompatible, and bareLiteralstays incompatible.How did you test it?
test/core/test_type_utils.py. That list also asserts the reverse direction is incompatible. The new cases coverstr,int, enum,Optional/PEP 604 unions, mixed literal to a union of types or literals, andlist[Literal[...]] -> list[str].test_connect_literal_output_to_str_inputtotest/core/pipeline/test_pipeline_base.py.hatch run test:unit test/core test/components/routers test/components/converters/test_output_adapter.py: 2154 passed.hatch run fmtandhatch run test:typesare clean.Notes for the reviewer
The change is a single early branch in
_strict_types_are_compatible, placed before the genericUnionreceiver branch so mixed literals can be split per value. A side effect:Literal[...] -> list[T]now gets the existingWRAPconversion, because wrapping reuses the strict check on the inner type.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.🤖 Generated with Claude Code