Dispatch PEP 604 unions (X | Y) in TypeParser.get_parser (#558)#562
Open
CodersAcademy006 wants to merge 1 commit into
Open
Dispatch PEP 604 unions (X | Y) in TypeParser.get_parser (#558)#562CodersAcademy006 wants to merge 1 commit into
CodersAcademy006 wants to merge 1 commit into
Conversation
get_origin() returns types.UnionType for PEP 604 unions, not typing.Union, so annotations like 'str | None' fell through to 'Unsupported type'. Recognize types.UnionType alongside Union at both dispatch sites; parse_union already handles the members via get_args. Adds a regression test that fails without this change. Closes NVIDIA-NeMo#558 Signed-off-by: Srijan Upadhyay <srjnupadhyay@gmail.com>
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.
Summary
get_origin()returnstypes.UnionTypefor PEP 604 unions (X | None,X | Y), nottyping.Union, soTypeParser.get_parserfell through to "Unsupported type". Any CLI entrypoint using modern union syntax failed to parse. This recognizestypes.UnionTypealongsideUnionat both dispatch sites;parse_unionalready handles the members viaget_args.Testing
Added
test_modern_pep604_union_type_hints(the existingtest_modern_union_type_hints/test_modern_optional_type_hintsonly coverUnion[...]/Optional[...], not pipe syntax). Verified it fails without the fix and passes with it; fulltest_cli_parser.pysuite green (80 passed):Closes #558
cc @hemildesai @marcromeyn