Skip to content

fix(cli): resolve string and future annotations in cli parser (#374) - #613

Open
ManoharPaturi wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
ManoharPaturi:fix/cli-resolve-string-annotations-374
Open

ManoharPaturi wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
ManoharPaturi:fix/cli-resolve-string-annotations-374

Conversation

@ManoharPaturi

Copy link
Copy Markdown

Fixes #374.

Motivation

When recipes or functions are defined in modules with from __future__ import annotations (or use string annotations / ForwardRefs), parameter annotations are stored as string expressions (e.g. 'int', 'str', 'list[str]', 'int | None').

Previously, _maybe_resolve_annotation only queried _resolve_type_checking_annotation, which scanned if TYPE_CHECKING: blocks in AST. String annotations for built-in types (like 'int') or module globals were never resolved to type objects, causing TypeParser.parse to fall through to UnknownTypeError: Unsupported type: int.

Solution

  1. In nemo_run/cli/cli_parser.py:
    • Added _resolve_string_annotation which resolves string annotations by first checking builtins (e.g. int, str, float, bool), then evaluating in the namespace of builtins, typing, and the target function/class's module globals, and falling back to AST TYPE_CHECKING imports.
    • Updated _maybe_resolve_annotation to use _resolve_string_annotation for string and ForwardRef annotations, and support types.UnionType (PEP 604 X | Y).
    • Added a check in TypeParser.get_parser to inspect builtins when annotation is a string matching a built-in type name.
  2. Added unit tests in test/cli/test_cli_parser.py covering scalar string annotations, container string annotations, and PEP 604 unions.

All 82 tests in test/cli/test_cli_parser.py pass cleanly.

…-NeMo#374)

Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 17, 2026 09:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

CLI parser throws an error when providing a config via yaml flag

2 participants