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

Fails to parse dict options #335

Open
chanind opened this issue Dec 19, 2024 · 0 comments
Open

Fails to parse dict options #335

chanind opened this issue Dec 19, 2024 · 0 comments

Comments

@chanind
Copy link

chanind commented Dec 19, 2024

Describe the bug

Apologies if I'm overlooking something in the docs, but I can't figure out how to get simple_parsing to parse a dict option. No matter how I pass a dict value, I get an error saying invalid dict value.

To Reproduce

from dataclasses import dataclass
from simple_parsing import ArgumentParser

@dataclass
class Config:
    options: dict | None = None

parser = ArgumentParser()
parser.add_arguments(Config, dest="config")

# fails with error
parser.parse_args(["--options", '{"x": 2}']).config

# also fails with error
parser.parse_args(["--options", "x=2"]).config

Expected behavior
It should return a dataclass with {"x": 2} or {"x": "2"} as option values

Actual behavior

invalid dict value error

Desktop (please complete the following information):

  • Version 0.1.6
  • Python version: 3.11

Additional context
A reproduction of this is in colab here: https://colab.research.google.com/drive/1LcDSctd9mbi5U-yz2kjuJJHI-n00RQDR#scrollTo=Ubd2JP002p6C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant