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

Bug with subgroups and None #306

Open
tachyonicClock opened this issue Feb 9, 2024 · 1 comment
Open

Bug with subgroups and None #306

tachyonicClock opened this issue Feb 9, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@tachyonicClock
Copy link

Describe the bug
When using the simple_parsing.subgroups function inside an optional child
data class, the default None value is not respected.

To Reproduce

import simple_parsing
from dataclasses import dataclass
from typing import Optional


@dataclass
class SubgroupA:
    pass

@dataclass
class SubgroupB:
    pass

@dataclass
class Child:
    subgroups: SubgroupA | SubgroupB = simple_parsing.subgroups(
        {
            "a": SubgroupA,
            "b": SubgroupB,
        },
        default="a"
    )

@dataclass
class Options:
    child: Optional[Child] = None

options: Options = simple_parsing.parse(Options, args=[])

print(options)

Expected behavior

The child field should be None, as it is the default value.

Options(child=None)

Actual behavior

The child field is erroneously set to Child(subgroups=SubgroupA()).

Options(child=Child(subgroups=SubgroupA()))

Desktop (please complete the following information):

  • Version 0.1.4
  • Python version: 3.10.13

Additional context
There is no additional context.

@lebrice
Copy link
Owner

lebrice commented Feb 14, 2024

Thanks for posting @tachyonicClock!
I'll take a look, but don't expect a quick fix, I'm planning a major refactor of the implementation for subgroups at the moment, which should hopefully make it a lot easier to fix these kinds of issues.

@lebrice lebrice self-assigned this Feb 14, 2024
@lebrice lebrice added the bug Something isn't working label Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants