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

Adds auto-config support for pydantic.Field #303

Merged
merged 4 commits into from
Sep 1, 2022
Merged

Adds auto-config support for pydantic.Field #303

merged 4 commits into from
Sep 1, 2022

Conversation

rsokl
Copy link
Contributor

@rsokl rsokl commented Sep 1, 2022

Given:

from pydantic.dataclasses import dataclass as pyd_dataclass
from pydantic import Field

@pyd_dataclass
class A:
    x: int = Field(default=2, gt=0, lt=3)

Before:

>>> from hydra_zen import builds
>>> builds(A, populate_full_signature=True)  # presence of `pydantic.Field` causes error
---------------------------------------------------------------------------
HydraZenUnsupportedPrimitiveError: Building: A ..
 The configured value default=2 gt=0 lt=3 extra={}, 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 'pydantic.fields.FieldInfo'>, ...)` create a config for this particular value.

After

>>> from hydra_zen import builds, just, instantiate
>>> Conf = builds(A, populate_full_signature=True)
>>> instantiate(Conf)
A(x=2)
>>> just(A.x)
2

@rsokl rsokl added the enhancement New feature or request label Sep 1, 2022
@rsokl rsokl added this to the hydra-zen 0.8.0 milestone Sep 1, 2022
@rsokl rsokl changed the title Add auto-config support for pydantic.Field Adds auto-config support for pydantic.Field Sep 1, 2022
@rsokl rsokl merged commit 18b1f09 into main Sep 1, 2022
@rsokl rsokl deleted the pydantic-Field branch September 1, 2022 13:16
@rsokl
Copy link
Contributor Author

rsokl commented Sep 1, 2022

close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant