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

Add support for builds(Dataclass, populate_full_signature=True) when dataclass has default factory fields #299

Merged
merged 4 commits into from
Aug 19, 2022

Conversation

rsokl
Copy link
Contributor

@rsokl rsokl commented Aug 19, 2022

Closes #295

from typing import Any
from hydra_zen import builds, instantiate

from dataclasses import field, dataclass

@dataclass
class A:
    x: Any = field(default_factory=lambda : [1, 2, 3])

Before:

>>> builds(A, populate_full_signature=True)
HydraZenUnsupportedPrimitiveError: Building: A ..
 The configured value <factory>, for field `x`, is not supported by Hydra -- serializing or instantiating this config would ultimately result in an error.

Consider using `hydra_zen.builds(<class 'dataclasses._HAS_DEFAULT_FACTORY_CLASS'>, ...)` create a config for this particular value.

After

>>> Conf = builds(A, populate_full_signature=True)
>>> instantiate(Conf)
A(x=[1, 2, 3])

@rsokl rsokl merged commit 7675970 into main Aug 19, 2022
@rsokl rsokl deleted the default-factory branch August 19, 2022 22:26
@rsokl rsokl added this to the hydra-zen 0.8.0 milestone Aug 28, 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

Successfully merging this pull request may close these issues.

Add support for builds(Dataclass, populate_full_signature=True) when Dataclass has default factory
1 participant