Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #322 (Union[Literal, ...]) #325

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions test/test_literal.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
Comment on lines +137 to +138

Choose a reason for hiding this comment

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

This should fail, right?

Loading