Fix Python 3.10+ pipe syntax with create_partial #1537
Closed
+64
−3
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.
Fix Python 3.10+ pipe syntax with create_partial
Fixes #1523
Description
This PR fixes an issue where using Python 3.10+ pipe syntax for Union types (
str | None
) withcreate_partial
method would crash with a TypeError:type 'types.UnionType' is not subscriptable
. After this fix, both syntaxes (Union[str, None]
andstr | None
) are supported.Changes
_process_generic_arg
to handletypes.UnionType
from Python 3.10+ properly_wrap_models
to handletypes.UnionType
from Python 3.10+ properlyTesting
Added tests that verify the fix works correctly:
tests/dsl/test_union_pipe.py
- Tests for_process_generic_arg
functiontests/llm/test_openai/test_pipe_syntax.py
- Tests forPartial
class with pipe syntaxLink to Devin run: https://app.devin.ai/sessions/42638ce64e364908a91a6ed24cb022d4
Requested by: Jason Liu (work@jxnl.co)