Skip to content

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

Merged
ko3n1g merged 3 commits into
NVIDIA-NeMo:mainfrom
CodersAcademy006:fix/pep604-union-dispatch
Aug 7, 2026
Merged

Dispatch PEP 604 unions (X | Y) in TypeParser.get_parser (#558)#562
ko3n1g merged 3 commits into
NVIDIA-NeMo:mainfrom
CodersAcademy006:fix/pep604-union-dispatch

Conversation

@CodersAcademy006

Copy link
Copy Markdown
Contributor

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>
@CodersAcademy006

Copy link
Copy Markdown
Contributor Author

@ko3n1g @chtruong814 pairing this with #561, same situation: open since July 14, no reviewer assigned, no comments.

get_origin() returns types.UnionType for PEP 604 unions such as X | None, not typing.Union, so TypeParser.get_parser in nemo_run/cli/cli_parser.py fell through to "Unsupported type" and any entrypoint annotated with modern union syntax failed to parse. This recognises types.UnionType alongside Union at both dispatch points and adds tests for it. Closes #558.

Copy link
Copy Markdown
Contributor

PR #562 — LGTM
Blocking findings: None.
Non-blocking findings: None. nemo_run/cli/cli_parser.py:689 and :708 route types.UnionType to the existing union parser, whose get_args() handling already supports both alternatives and None. test/cli/test_cli_parser.py:884-905 covers container unions and str | None through parse_cli_args.
Validation gaps: Only successful DCO is visible; no test check is recorded.

@ko3n1g
ko3n1g enabled auto-merge (squash) August 7, 2026 11:46
@ko3n1g
ko3n1g merged commit 9afd8bf into NVIDIA-NeMo:main Aug 7, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

3 participants