Skip to content

Dispatch PEP 604 unions (X | Y) in TypeParser.get_parser (#558)#562

Open
CodersAcademy006 wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
CodersAcademy006:fix/pep604-union-dispatch
Open

Dispatch PEP 604 unions (X | Y) in TypeParser.get_parser (#558)#562
CodersAcademy006 wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
CodersAcademy006:fix/pep604-union-dispatch

Conversation

@CodersAcademy006

Copy link
Copy Markdown

Summary

get_origin() returns types.UnionType for PEP 604 unions (X | None, X | Y), not typing.Union, so TypeParser.get_parser fell through to "Unsupported type". Any CLI entrypoint using modern union syntax failed to parse. This recognizes types.UnionType alongside Union at both dispatch sites; parse_union already handles the members via get_args.

Testing

Added test_modern_pep604_union_type_hints (the existing test_modern_union_type_hints/test_modern_optional_type_hints only cover Union[...]/Optional[...], not pipe syntax). Verified it fails without the fix and passes with it; full test_cli_parser.py suite green (80 passed):

# without fix:  1 failed
# with fix:     1 passed;  full file: 80 passed

Closes #558

cc @hemildesai @marcromeyn

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeParser.get_parser does not dispatch PEP 604 unions (X | None) — "Unsupported type", order-dependent via lru_cache

1 participant