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

dataclass decorator not working as expected #14

Closed
rafi-cohen opened this issue Mar 24, 2021 · 1 comment · Fixed by #15
Closed

dataclass decorator not working as expected #14

rafi-cohen opened this issue Mar 24, 2021 · 1 comment · Fixed by #15

Comments

@rafi-cohen
Copy link
Contributor

Hi,

I seem to be running into a couple of issues when using the decorator that was recently added in #9:

  1. It does not work with optional keyword arguments:
from argparse_dataclass import dataclass

@dataclass(frozen=True)
class Opt:
    x: int = 42
    y: bool = False

Error: TypeError: cls must be a dataclass
It seems that cls here is actually real_dataclass.wrap.

  1. It does not behave like a regular dataclass:
from argparse_dataclass import dataclass

@dataclass
class Opt:
    x: int = 42
    y: bool = False

opt = Opt()
print(opt.x)

Error: AttributeError: 'Inner' object has no attribute 'x'
Looks like Opt was "replaced" with Inner, which is defined in argparse_dataclass.dataclass.

@rafi-cohen
Copy link
Contributor Author

I think 1 can be fixed by doing something similar to real_dataclass - the return value depends on whether it was called with parentheses or not.
And 2 can probably be fixed by not defining a new class, but rather modifying the class we're decorating.

I'll try it out soon.

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

Successfully merging a pull request may close this issue.

1 participant