diff --git a/test/test_literal.py b/test/test_literal.py index caac3be4..796953b3 100644 --- a/test/test_literal.py +++ b/test/test_literal.py @@ -1,10 +1,9 @@ import enum import sys from dataclasses import dataclass -from typing import Any, List, NamedTuple, Optional +from typing import Any, List, Literal, NamedTuple, Optional, Union import pytest -from typing_extensions import Literal from .testutils import ( TestSetup, @@ -118,3 +117,22 @@ def test_reproduce_issue_259_parsing_literal_py39(): "argument --param: invalid typing.Literal['bar', 'biz'] value: 'biz'" ): assert SomeFoo.setup("").param == "biz" + + +@dataclass +class Foo: + bar: Union[Literal["a"], int] = "a" + + +def test_issue_322(): + """Test for https://github.com/lebrice/SimpleParsing/issues/322.""" + from simple_parsing import parse + + assert parse(Foo, args="") == Foo() + assert parse(Foo, args="--bar=a") == Foo(bar="a") + with raises_invalid_choice(): + assert parse(Foo, args="--bar=b") + + assert parse(Foo, args="--bar=123") == Foo(bar=123) + # TODO: What about this again? + assert parse(Foo, args="--bar=1.23") == Foo(bar=1)