Skip to content

CLI parser crashes on unparameterized list/dict annotations (x: list); Union[list, str] silently misparses to string #606

Description

@ManoharPaturi

Description

Entry points using unparameterized collection annotations cannot be set from the CLI:

  • def f(tags: list) + tags=[1, 2, 3]ListParseError: Invalid list: tuple index out of range
  • def f(mapping: dict) + mapping={'a': 1}DictParseError: Invalid dict: not enough values to unpack
  • Optional[list] / Optional[dict] fail the same way through the Union parser
  • bare typing.List / typing.Dict crash with IndexError in _maybe_resolve_annotation
  • silent misparse: Union[list, str] with value [1, 2] returns the string '[1, 2]' because the failed list parse makes the Union fall through to str

Steps to reproduce

import nemo_run as run

@run.cli.entrypoint(skip_confirmation=True)
def train(tags: list = None):
    print(tags)

if __name__ == "__main__":
    run.cli.main(train)
$ python app.py tags=[1,2,3]
nemo_run.cli.cli_parser.ListParseError: ... Invalid list: tuple index out of range

Expected behavior

tags parses to the list [1, 2, 3] (no element type known → no coercion), matching Python semantics of bare list/dict.

Actual behavior

parse_list/parse_dict index get_args(annotation) unconditionally; get_args(list) is empty, so parsing crashes (or misparses inside a Union).

#558 was a different defect in the same area (PEP-604 dispatch) — these still reproduce on current main.

Environment

nemo-run main (b85eb67), Python 3.12, macOS

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions