Dispatch PEP 604 unions (X | Y) in TypeParser.get_parser (#558) - #562
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>
|
@ko3n1g @chtruong814 pairing this with #561, same situation: open since July 14, no reviewer assigned, no comments.
|
|
PR #562 — LGTM |
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