SimpleParsing icon indicating copy to clipboard operation
SimpleParsing copied to clipboard

`Union[Literal, ...]` is unusable

Open JasonGross opened this issue 1 year ago • 0 comments

To Reproduce

from dataclasses import dataclass
from typing import Literal, Union
import simple_parsing

@dataclass
class Foo:
    bar: Union[Literal["a"], dict] = "a"

parser = simple_parsing.ArgumentParser()
parser.add_arguments(
    Foo,
    dest="foo",
    default=Foo(),
)
parser.parse_args()

Expected behavior The code should run, just like it does if I replace Union[Literal["a"], dict] with Literal["a"]

Actual behavior

$ python issue.py
Couldn't parse value a, returning the value as-is. (exceptions: [TypeError('Cannot instantiate typing.Literal'), ValueError('dictionary update sequence element #0 has length 1; 2 is required')])
usage: test.py [-h] [--bar Literal|dict]
test.py: error: argument --bar: invalid Literal|dict value: 'a'

Desktop (please complete the following information):

  • simple-parsing = "^0.1.5"
  • Python version: 3.11

JasonGross avatar Aug 21 '24 10:08 JasonGross