Skip to content

Union[Literal, ...] is unusable #322

Closed

Description

@JasonGross

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

Activity

  1. added a commit that references this issue on Aug 21, 2024
  2. added a commit that references this issue on Sep 5, 2024
  3. FranzKnut commented on Jul 20, 2026

    @FranzKnut

    This issue is still unresolved, right?

  4. lebrice commented on Jul 27, 2026

    @lebrice
    Owner

    Hi @FranzKnut , indeed I think this might have slipped my mind. There is a draft PR with a fix for this, (#325) I'll see if I can update it and merge it soon. Thanks for the reminder! :)

  5. added a commit that references this issue on Jul 27, 2026
    cd57820
  6. added a commit that references this issue on Jul 27, 2026
    7a706be
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions