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

TypeError: non-default argument 'value' follows default argument #305

Open
George-Ogden opened this issue Aug 31, 2023 · 1 comment
Open

Comments

@George-Ogden
Copy link

I'm trying to inherit from a dataclass with an optional id in the parent, however, I am seeing TypeError: non-default argument 'value' follows default argument. This is the minimal code to reproduce.

from typing import Optional
import chex

@chex.dataclass
class Base:
    idx: Optional[int] = None

@chex.dataclass
class Derived(Base):
    value: int

This is an issue with the dataclasses library rather than chex.dataclasses, however, according to https://stackoverflow.com/questions/51575931/class-inheritance-in-python-3-7-dataclasses#answer-69822584, it is possible to fix by setting kw_only=True.

@George-Ogden
Copy link
Author

Sorry, I see this has been fixed in a later version when the following modification is made to the code:

from typing import Optional
import chex

@chex.dataclass(kw_only=True)
class Base:
    idx: Optional[int] = None

@chex.dataclass
class Derived(Base):
    value: int

However, would it be worth making this the default behaviour as chex.dataclass objects are all kw_only by default?

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