Skip to content

Commit

Permalink
Remove builds_bases option from make_custom_builds_fn (#306)
Browse files Browse the repository at this point in the history
* remove builds_bases from make_custom_builds_fn

* remove straggler code and fix tests

* remove builds_bases from docs

* changelog

Co-authored-by: rsokl <ryan.soklaski@ll.mit.edu>
  • Loading branch information
rsokl and rsokl committed Sep 13, 2022
1 parent 7f6c6b4 commit 879b564
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 150 deletions.
4 changes: 4 additions & 0 deletions docs/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ Compatibility-Breaking Changes
------------------------------
This release drops support for Python 3.6. If you require Python 3.6, please restrict your hydra-zen installation dependency as `hydra-zen<0.8.0`.

Specifing `make_custom_builds_fn([...], builds_bases=<...>)` was deprecated in
hydra-zen 0.7.0 (:pull:`263`). Accordingly, this option has now been removed from
:func:`hydra_zen.make_custom_builds_fn`.

The addition of auto-config support for dataclasses (:pull:`301`) changes the default
behaviors of :func:`~hydra_zen.just` and :func:`~hydra_zen.builds`. Previously, all
dataclass types and instances lacking a `_target_` field would be left unprocessed by
Expand Down
81 changes: 7 additions & 74 deletions src/hydra_zen/structured_configs/_make_custom_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,14 @@
# SPDX-License-Identifier: MIT
# pyright: strict
import inspect
import warnings
from functools import wraps
from typing import (
Any,
Callable,
Dict,
Mapping,
Optional,
Tuple,
Type,
Union,
cast,
overload,
)
from typing import Any, Callable, Dict, Mapping, Optional, Union, cast, overload

from typing_extensions import Final, Literal

from hydra_zen.errors import HydraZenDeprecationWarning
from hydra_zen.typing import ZenWrappers
from hydra_zen.typing._builds_overloads import FullBuilds, PBuilds, StdBuilds
from hydra_zen.typing._implementations import DataClass_, ZenConvert
from hydra_zen.typing._implementations import ZenConvert

from ._implementations import builds

Expand All @@ -38,7 +25,7 @@
del _builds_sig


# partial=False, pop-sig=True; no parents
# partial=False, pop-sig=True
@overload
def make_custom_builds_fn(
*,
Expand All @@ -49,7 +36,6 @@ def make_custom_builds_fn(
hydra_recursive: Optional[bool] = ...,
hydra_convert: Optional[Literal["none", "partial", "all"]] = ...,
frozen: bool = ...,
builds_bases: Tuple[()] = ...,
zen_convert: Optional[ZenConvert] = ...,
) -> FullBuilds: # pragma: no cover
...
Expand All @@ -66,13 +52,12 @@ def make_custom_builds_fn(
hydra_recursive: Optional[bool] = ...,
hydra_convert: Optional[Literal["none", "partial", "all"]] = ...,
frozen: bool = ...,
builds_bases: Tuple[Type[DataClass_], ...] = ...,
zen_convert: Optional[ZenConvert] = ...,
) -> PBuilds: # pragma: no cover
...


# partial=False, pop-sig=False, no parents
# partial=False, pop-sig=False
@overload
def make_custom_builds_fn(
*,
Expand All @@ -83,13 +68,12 @@ def make_custom_builds_fn(
hydra_recursive: Optional[bool] = ...,
hydra_convert: Optional[Literal["none", "partial", "all"]] = ...,
frozen: bool = ...,
builds_bases: Tuple[()] = ...,
zen_convert: Optional[ZenConvert] = ...,
) -> StdBuilds: # pragma: no cover
...


# partial=False, pop-sig=bool, no parents
# partial=False, pop-sig=bool
@overload
def make_custom_builds_fn(
*,
Expand All @@ -100,29 +84,11 @@ def make_custom_builds_fn(
hydra_recursive: Optional[bool] = ...,
hydra_convert: Optional[Literal["none", "partial", "all"]] = ...,
frozen: bool = ...,
builds_bases: Tuple[()] = ...,
zen_convert: Optional[ZenConvert] = ...,
) -> Union[FullBuilds, StdBuilds]: # pragma: no cover
...


# partial=False, pop-sig=bool, with parents
@overload
def make_custom_builds_fn(
*,
zen_partial: Literal[False, None] = ...,
populate_full_signature: bool = ...,
zen_wrappers: ZenWrappers[Callable[..., Any]] = ...,
zen_meta: Optional[Mapping[str, Any]] = ...,
hydra_recursive: Optional[bool] = ...,
hydra_convert: Optional[Literal["none", "partial", "all"]] = ...,
frozen: bool = ...,
builds_bases: Tuple[Type[DataClass_], ...],
zen_convert: Optional[ZenConvert] = ...,
) -> StdBuilds: # pragma: no cover
...


# partial=bool, pop-sig=False
@overload
def make_custom_builds_fn(
Expand All @@ -134,30 +100,12 @@ def make_custom_builds_fn(
hydra_recursive: Optional[bool] = ...,
hydra_convert: Optional[Literal["none", "partial", "all"]] = ...,
frozen: bool = ...,
builds_bases: Tuple[Type[DataClass_], ...] = ...,
zen_convert: Optional[ZenConvert] = ...,
) -> Union[PBuilds, StdBuilds]: # pragma: no cover
...


# partial=bool, pop-sig=bool, with parents
@overload
def make_custom_builds_fn(
*,
zen_partial: Union[bool, None],
populate_full_signature: bool,
zen_wrappers: ZenWrappers[Callable[..., Any]] = ...,
zen_meta: Optional[Mapping[str, Any]] = ...,
hydra_recursive: Optional[bool] = ...,
hydra_convert: Optional[Literal["none", "partial", "all"]] = ...,
frozen: bool = ...,
builds_bases: Tuple[Type[DataClass_], ...],
zen_convert: Optional[ZenConvert] = ...,
) -> Union[PBuilds, StdBuilds]: # pragma: no cover
...


# partial=bool, pop-sig=bool, no parents
# partial=bool, pop-sig=bool
@overload
def make_custom_builds_fn(
*,
Expand All @@ -168,7 +116,6 @@ def make_custom_builds_fn(
hydra_recursive: Optional[bool] = ...,
hydra_convert: Optional[Literal["none", "partial", "all"]] = ...,
frozen: bool = ...,
builds_bases: Tuple[()] = ...,
zen_convert: Optional[ZenConvert] = ...,
) -> Union[FullBuilds, PBuilds, StdBuilds]: # pragma: no cover
...
Expand All @@ -183,7 +130,6 @@ def make_custom_builds_fn(
hydra_recursive: Optional[bool] = None,
hydra_convert: Optional[Literal["none", "partial", "all"]] = None,
frozen: bool = False,
builds_bases: Tuple[Type[DataClass_], ...] = (),
zen_convert: Optional[ZenConvert] = None,
) -> Union[FullBuilds, PBuilds, StdBuilds]:
"""Returns the `builds` function, but with customized default values.
Expand Down Expand Up @@ -225,9 +171,6 @@ def make_custom_builds_fn(
frozen : bool, optional (default=False)
Specifies a new the default value for ``builds(..., frozen=<..>)``
builds_bases : Tuple[DataClass, ...]
Specifies a new the default value for ``builds(..., builds_bases=<..>)``
Returns
-------
custom_builds
Expand Down Expand Up @@ -288,7 +231,7 @@ def make_custom_builds_fn(
<Validation error: "c" is not "a" or "b">
"""

excluded_fields = {"dataclass_name", "hydra_defaults"}
excluded_fields = frozenset({"dataclass_name", "hydra_defaults", "builds_bases"})
LOCALS = locals()

# Ensures that new defaults added to `builds` must be reflected
Expand All @@ -302,16 +245,6 @@ def make_custom_builds_fn(
# let `builds` validate the new defaults!
builds(builds, **_new_defaults)

if _new_defaults["builds_bases"]:
warnings.warn(
HydraZenDeprecationWarning(
"Specifying `make_custom_builds_fn(builds_bases=<...>)` is deprecated "
"as of hydra-zen 0.7.0. It will be an error in hydra-zen 0.9.0. "
"\n`builds_bases` must be specified via `builds` manually."
),
stacklevel=2,
)

@wraps(builds)
def wrapped(*args: Any, **kwargs: Any):
merged_kwargs: Dict[str, Any] = {}
Expand Down
68 changes: 0 additions & 68 deletions tests/annotations/declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,20 +694,6 @@ def f(x: int, y: str, z: bool = False):
expected_text="Type[Builds[(x: int, y: str, z: bool = False) -> Literal[1]]]",
)

Parent = make_config(x=1)

# specifying parent should produce default `builds`
builds2 = make_custom_builds_fn(
populate_full_signature=True, builds_bases=(Parent,)
)

Conf2 = builds2(f)

reveal_type(
Conf2,
expected_text="Type[Builds[(x: int, y: str, z: bool = False) -> Literal[1]]]",
)


def check_make_custom_builds_pop_sig():
def f(x: int, y: str, z: bool = False):
Expand Down Expand Up @@ -748,19 +734,6 @@ def f(x: int, y: str, z: bool = False) -> int:
expected_text="Type[ZenPartialBuilds[(x: int, y: str, z: bool = False) -> int]] | Type[HydraPartialBuilds[(x: int, y: str, z: bool = False) -> int]]",
)

Parent = make_config(x=1)

partial_builds3 = make_custom_builds_fn(
zen_partial=True, builds_bases=(Parent,), populate_full_signature=True
)

Conf3 = partial_builds3(f)

reveal_type(
Conf3,
expected_text="Type[ZenPartialBuilds[(x: int, y: str, z: bool = False) -> int]] | Type[HydraPartialBuilds[(x: int, y: str, z: bool = False) -> int]]",
)


def check_protocol_compatibility():
def f_builds(x: Type[Builds[Any]]):
Expand Down Expand Up @@ -941,18 +914,6 @@ def f(x: int):


def check_make_custom_builds_overloads(boolean: bool, optional_boolean: Optional[bool]):
Parent = builds(int)

# Returns `StdBuilds`
reveal_type(
make_custom_builds_fn(populate_full_signature=boolean, builds_bases=(Parent,)),
expected_text="StdBuilds",
)

reveal_type(
make_custom_builds_fn(builds_bases=(Parent,)),
expected_text="StdBuilds",
)

# partial = False, pop-sig = False
reveal_type(make_custom_builds_fn(zen_partial=False), expected_text="StdBuilds")
Expand All @@ -973,13 +934,6 @@ def check_make_custom_builds_overloads(boolean: bool, optional_boolean: Optional
expected_text="PBuilds",
)

reveal_type(
make_custom_builds_fn(
zen_partial=True, populate_full_signature=False, builds_bases=(Parent,)
),
expected_text="PBuilds",
)

# Returns `PBuilds | StdBuilds``
reveal_type(
make_custom_builds_fn(zen_partial=False, populate_full_signature=boolean),
Expand All @@ -997,28 +951,6 @@ def check_make_custom_builds_overloads(boolean: bool, optional_boolean: Optional
),
expected_text="PBuilds | StdBuilds",
)
reveal_type(
make_custom_builds_fn(
populate_full_signature=True,
zen_partial=optional_boolean,
builds_bases=(Parent,),
),
expected_text="PBuilds | StdBuilds",
)

reveal_type(
make_custom_builds_fn(
populate_full_signature=boolean,
zen_partial=optional_boolean,
builds_bases=(Parent,),
),
expected_text="PBuilds | StdBuilds",
)

reveal_type(
make_custom_builds_fn(zen_partial=optional_boolean, builds_bases=(Parent,)),
expected_text="PBuilds | StdBuilds",
)

# Returns `FullBuilds | PBuilds | StdBuilds`
reveal_type(
Expand Down
10 changes: 2 additions & 8 deletions tests/test_make_custom_builds_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from hypothesis import assume, example, given

from hydra_zen import builds, make_custom_builds_fn, to_yaml
from hydra_zen.errors import HydraZenDeprecationWarning
from tests.custom_strategies import partitions, valid_builds_args

_builds_sig = inspect.signature(builds)
Expand Down Expand Up @@ -46,7 +45,7 @@ def _corrupt_kwargs(kwargs: dict):


@given(
bad_kwargs=valid_builds_args().map(_corrupt_kwargs),
bad_kwargs=valid_builds_args(excluded=("builds_bases",)).map(_corrupt_kwargs),
)
def test_raises_on_bad_defaults(bad_kwargs):
try:
Expand All @@ -69,7 +68,7 @@ def f2(x, y: str):
"ignore:A structured config was supplied for `zen_wrappers`"
)
@given(
kwargs=partitions(valid_builds_args(), ordered=False),
kwargs=partitions(valid_builds_args(excluded=("builds_bases",)), ordered=False),
target=st.sampled_from([f1, f2]),
)
def test_make_builds_fn_produces_builds_with_expected_defaults_and_behaviors(
Expand All @@ -85,8 +84,3 @@ def test_make_builds_fn_produces_builds_with_expected_defaults_and_behaviors(
# this should be the same as passing all of these args directly to vanilla builds
via_builds = builds(target, **kwargs_passed_through, **kwargs_as_defaults)
assert to_yaml(via_custom) == to_yaml(via_builds)


def test_builds_bases_deprecation():
with pytest.warns(HydraZenDeprecationWarning):
make_custom_builds_fn(builds_bases=((builds(int),)))

0 comments on commit 879b564

Please sign in to comment.