Repository: mit-ll-responsible-ai/hydra-zen

Issue:
`make_config` is too aggressive with type-widening
https://github.com/mit-ll-responsible-ai/hydra-zen/blob/00c50b770af2644551c30b821ff61f740fd4399a/src/hydra_zen/structured_configs/_implementations.py#L2405-L2409

needs identical fix from: https://github.com/mit-ll-responsible-ai/hydra-zen/pull/185

Discussion:

Patch:
diff --git a/docs/source/changes.rst b/docs/source/changes.rst
index 6d4ee28a..00bf9bd7 100644
--- a/docs/source/changes.rst
+++ b/docs/source/changes.rst
@@ -19,7 +19,7 @@ Improvements
 ------------
 - Fixed an edge case `caused by an upstream bug in inspect.signature <https://bugs.python.org/issue40897>`_, which prevented :func:`~hydra_zen.builds` from accessing the appropriate signature for some target classes. This affected a couple of popular PyTorch classes, such as ``torch.utils.data.DataLoader`` and ``torch.utils.data.Dataset``. See :pull:`189` for examples. 
 - When appropriate, ``builds(<target>, ...)`` will now consult ``<target>.__new__`` to acquire the type-hints of the target's signature. See :pull:`189` for examples. 
-- Fixed an edge case in the :ref:`type-widening behavior <type-support>` in :func:`~hydra_zen.builds` where a ``Builds``-like annotation would be widened to ``Any``; this widening was too aggressive. See :pull:`185` for examples. 
+- Fixed an edge case in the :ref:`type-widening behavior <type-support>` in both :func:`~hydra_zen.builds` and :func:`~hydra_zen.make_config` where a ``Builds``-like annotation would be widened to ``Any``; this widening was too aggressive. See :pull:`185` for examples. 
 - Fixed incomplete annotations for ``builds(..., zen_wrappers=<..>)``. See :pull:`180`
 
 Notes
diff --git a/src/hydra_zen/structured_configs/_implementations.py b/src/hydra_zen/structured_configs/_implementations.py
index 2fb0c0b5..a34671a6 100644
--- a/src/hydra_zen/structured_configs/_implementations.py
+++ b/src/hydra_zen/structured_configs/_implementations.py
@@ -2402,10 +2402,12 @@ def make_config(
             (
                 str(f.name),
                 (
-                    f.hint
                     # f.default: Field
                     # f.default.default: Any
-                    if not is_builds(f.default.default) or hydra_recursive is False  # type: ignore
+                    f.hint
+                    if hydra_recursive is False
+                    or not is_builds(f.default.default)  # type: ignore
+                    or is_builds(f.hint)
                     else Any
                 ),
                 f.default,


Test patch:
diff --git a/tests/test_make_config.py b/tests/test_make_config.py
index eaf8c9bc..20bc533f 100644
--- a/tests/test_make_config.py
+++ b/tests/test_make_config.py
@@ -1,9 +1,11 @@
+# Copyright (c) 2022 Massachusetts Institute of Technology
+# SPDX-License-Identifier: MIT
 import inspect
 import string
 from dataclasses import FrozenInstanceError
 from enum import Enum
 from itertools import chain
-from typing import Callable, Tuple, Union
+from typing import Any, Callable, Tuple, Union, get_type_hints
 
 import hypothesis.strategies as st
 import pytest
@@ -113,6 +115,7 @@ def test_to_yaml_validates_hydra_compat_types():
 @example(int)
 @example(str)
 @example(bool)
+@example(builds(int))
 @example(Tuple[int, str, bool])
 @example(Callable[[int], int])
 @example(Union[Callable, int])
@@ -291,3 +294,12 @@ def test_hydra_options(hydra_convert, hydra_recursive):
         assert c_yaml == "{}\n"  # yaml for empty config
     else:
         assert b_yaml.splitlines()[1:] == c_yaml.splitlines()
+
+
+def test_make_config_annotation_widening_behavior():
+    BuildsInt = builds(int)
+    Conf1 = make_config(a=ZenField(hint=BuildsInt, default=BuildsInt()))
+    assert get_type_hints(Conf1)["a"] is BuildsInt
+
+    Conf2 = make_config(b=ZenField(hint=int, default=BuildsInt()))
+    assert get_type_hints(Conf2)["b"] is Any