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

Subparsing issue with Union types #9

Closed
pculbertson opened this issue Sep 2, 2022 · 1 comment
Closed

Subparsing issue with Union types #9

pculbertson opened this issue Sep 2, 2022 · 1 comment

Comments

@pculbertson
Copy link

Hi Brent,

We hit another issue with some nested configs we're using -- basically something is going awry (I think) due to a type Union.

Here's a MWE:

import dataclasses
import dcargs

from typing import Tuple, Union

@dataclasses.dataclass(frozen=True)
class Subtype:
    data: int = 1
    
@dataclasses.dataclass(frozen=True)
class TypeA:
    subtype: Subtype = Subtype(1)

@dataclasses.dataclass(frozen=True)
class TypeB:
    subtype: Subtype = Subtype(2)
    
@dataclasses.dataclass(frozen=True)
class Wrapper:
    supertype: Union[TypeA, TypeB] = TypeA()
    
if __name__ == "__main__":
    wrapper = dcargs.cli(Wrapper) # errors when running with supertype:type-a
    print(wrapper)

If you put this in a module subparsers.py and run $ python subparsers.py, everything works; if you run $ python subparsers.py supertype:type-a, it throws the following error:

File "/opt/conda/lib/python3.7/site-packages/dcargs/_cli.py", line 272, in _cli_impl
    avoid_subparsers=avoid_subparsers,
  File "/opt/conda/lib/python3.7/site-packages/dcargs/_calling.py", line 169, in call_from_args
    avoid_subparsers=avoid_subparsers,
  File "/opt/conda/lib/python3.7/site-packages/dcargs/_calling.py", line 117, in call_from_args
    assert len(parser_definition.subparsers_from_name) > 0
AssertionError

Thanks again for the great package + sorry to raise obscure issues! No problem if this isn't high-priority.

@brentyi
Copy link
Owner

brentyi commented Sep 2, 2022

Thanks for the detailed reproduction instructions!!

This was actually already fixed in a different branch, I just pulled the changes into master and did a release. Should be resolved now. 🙂

@brentyi brentyi closed this as completed Sep 2, 2022
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

2 participants