nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: mit-ll-responsible-ai/hydra-zen
Pull request #119 (2021-10-05 20:54:13)

sanitized-type: fixes edge case with manually-constructed Union


Patch:
diff --git a/src/hydra_zen/structured_configs/_utils.py b/src/hydra_zen/structured_configs/_utils.py
index da64d1b2..0f906940 100644
--- a/src/hydra_zen/structured_configs/_utils.py
+++ b/src/hydra_zen/structured_configs/_utils.py
@@ -259,14 +259,14 @@ def sanitized_type(
         args = get_args(type_)
         if origin is Union:
             # Hydra only supports Optional[<type>] unions
-            if len(args) != 2 or type(None) not in args:
+            if len(args) != 2 or NoneType not in args:
                 # isn't Optional[<type>]
                 return Any
 
             args = cast(Tuple[type, type], args)
 
             optional_type, none_type = args
-            if not isinstance(None, none_type):
+            if none_type is not NoneType:
                 optional_type = none_type
             optional_type: Optional[Any]
             optional_type = sanitized_type(optional_type)


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 8036b80b..8811136a 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -93,6 +93,9 @@ class Color(enum.Enum):
     pass
 
 
+NoneType = type(None)
+
+
 @pytest.mark.parametrize(
     "in_type, expected_type",
     [
@@ -123,8 +126,8 @@ class Color(enum.Enum):
         (abc.Mapping, Any),
         (Union[str, int], Any),
         (Optional[frozenset], Any),
-        (Union[type(None), frozenset], Any),
-        (Union[type(None), int], Optional[int]),  # supported Optional
+        (Union[NoneType, frozenset], Any),
+        (Union[NoneType, int], Optional[int]),  # supported Optional
         (Optional[Color], Optional[Color]),
         (Optional[List[Color]], Optional[List[Color]]),
         (Optional[List[List[int]]], Optional[List[Any]]),
@@ -141,6 +144,8 @@ class Color(enum.Enum):
         (Tuple[str, ...], Tuple[str, ...]),
         (Tuple[str, str, str], Tuple[str, str, str]),
         (Tuple[List[int]], Tuple[Any]),
+        (Union[NoneType, Tuple[int, int]], Optional[Tuple[int, int]]),
+        (Union[Tuple[int, int], NoneType], Optional[Tuple[int, int]]),
     ],
 )
 def test_sanitized_type_expected_behavior(in_type, expected_type):
Repository: mit-ll-responsible-ai/hydra-zen
Pull request #177 (2021-12-06 23:33:31)

Revert compat-breaking enum change introduced in v0.4.0
In the release of `v0.4.0`, I failed to document the compatibility-breaking change in how we support enums. Furthermore, it came to my attention that the change could introduce substantial, cumbersome changes in how a user configures and launches an app that involve enums. Lastly, the change disabled Hydra's ability to validate enum-types.

Thus this PR reverts the enum-specific changes introduced in #163 . I.e. we once again defer to the default omegaconf/Hydra support for enums.


Patch:
diff --git a/src/hydra_zen/structured_configs/_implementations.py b/src/hydra_zen/structured_configs/_implementations.py
index 1f1f9c23..a0f546b5 100644
--- a/src/hydra_zen/structured_configs/_implementations.py
+++ b/src/hydra_zen/structured_configs/_implementations.py
@@ -598,18 +598,11 @@ def sanitized_default_value(
             resolved_value = conversion_fn(resolved_value)
             type_of_value = type(resolved_value)
 
-    if structured_conf_permitted and isinstance(resolved_value, Enum):
-        # Leverages programmatic access to enum member via value.
-        # E.g.
-        # >>> Color(1)
-        # <Color.RED: 1>
-        return builds(type(resolved_value), resolved_value.value)
-
     if type_of_value in HYDRA_SUPPORTED_PRIMITIVES or (
         structured_conf_permitted
         and (
             is_dataclass(resolved_value)
-            or isinstance(resolved_value, (ListConfig, DictConfig))
+            or isinstance(resolved_value, (Enum, ListConfig, DictConfig))
         )
     ):
         return resolved_value


Test patch:
diff --git a/tests/test_signature_parsing.py b/tests/test_signature_parsing.py
index aff19ce6..f80b65df 100644
--- a/tests/test_signature_parsing.py
+++ b/tests/test_signature_parsing.py
@@ -4,6 +4,7 @@
 import inspect
 from abc import ABC
 from dataclasses import dataclass
+from enum import Enum
 from inspect import Parameter
 from typing import Any, Callable, Dict, Mapping, Optional, Tuple, Type
 
@@ -373,3 +374,16 @@ def test_pop_full_sig_is_always_identical_to_manually_specifying_sig_args(
     note(to_yaml(Conf))
     note(to_yaml(ConfWithPopSig))
     assert to_yaml(Conf) == to_yaml(ConfWithPopSig)
+
+
+class Color(Enum):
+    red = 1
+    green = 2
+
+
+def f_with_color(x: Color = Color.red):
+    return x
+
+
+def test_populate_annotated_enum_regression():
+    assert instantiate(builds(f_with_color, populate_full_signature=True)) is Color.red
diff --git a/tests/test_value_conversion.py b/tests/test_value_conversion.py
index 049450cd..8a3b83c5 100644
--- a/tests/test_value_conversion.py
+++ b/tests/test_value_conversion.py
@@ -90,6 +90,10 @@ def test_value_supported_via_config_maker_functions(
     )
 
     if via_yaml:
+        if isinstance(value, Enum):
+            # Default omegaconf support for enums doesn't roundtrip from yamls
+            assume(False)
+
         Conf = OmegaConf.structured(to_yaml(Conf))
 
     conf = instantiate(Conf)
Repository: mit-ll-responsible-ai/hydra-zen
Pull request #193 (2022-01-10 15:22:22)

Internal fixes
`_get_version` was breaking on dev-versions. E.g. `0.2.4dev1`


Patch:
diff --git a/src/hydra_zen/_compatibility.py b/src/hydra_zen/_compatibility.py
index 383876ff..471440dc 100644
--- a/src/hydra_zen/_compatibility.py
+++ b/src/hydra_zen/_compatibility.py
@@ -21,7 +21,7 @@ class Version(NamedTuple):
 def _get_version(ver_str: str) -> Version:
     # Not for general use. Tested only for Hydra and OmegaConf
     # version string styles
-    major, minor, *_ = (int(v) for v in ver_str.split("."))
+    major, minor = (int(v) for v in ver_str.split(".")[:2])
     return Version(major=major, minor=minor)
 
 
diff --git a/src/hydra_zen/structured_configs/_implementations.py b/src/hydra_zen/structured_configs/_implementations.py
index 47ebd992..2fb0c0b5 100644
--- a/src/hydra_zen/structured_configs/_implementations.py
+++ b/src/hydra_zen/structured_configs/_implementations.py
@@ -1355,9 +1355,9 @@ def builds(
         if (
             inspect.isclass(target)
             and len(target.__mro__) > 2
-            and any("__new__" in parent.__dict__ for parent in target.__mro__[1:-1])
             and "__init__" in target.__dict__
             and "__new__" not in target.__dict__
+            and any("__new__" in parent.__dict__ for parent in target.__mro__[1:-1])
         ):
             _params = tuple(inspect.signature(target.__init__).parameters.items())
 


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 5a1999ac..e9974b5d 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -21,6 +21,7 @@ from omegaconf.errors import (
 from typing_extensions import Final, Literal
 
 from hydra_zen import builds, instantiate, mutable_value
+from hydra_zen._compatibility import Version, _get_version
 from hydra_zen.structured_configs._utils import (
     field,
     is_interpolated_string,
@@ -277,3 +278,27 @@ def test_strings_that_fail_to_interpolate_are_not_interpolated_strings(any_text)
 
     # If `any_text` is a valid interpolated string, then `out == 1`
     assert out == 1 or not is_interpolated_string(any_text)
+
+
+@pytest.mark.parametrize(
+    "version_string, expected",
+    [
+        ("1.2.0", Version(1, 2)),
+        ("2.1.0dev24", Version(2, 1)),
+    ],
+)
+def test_get_version(version_string, expected):
+    assert _get_version(version_string) == expected
+
+
+@pytest.mark.parametrize(
+    "smaller, larger",
+    [
+        (Version(1, 0), Version(2, 0)),
+        (Version(1, 0), Version(1, 1)),
+        (Version(1, 0, 0), Version(1, 0, 1)),
+        (Version(1, 0, 1), Version(1, 1, 0)),
+    ],
+)
+def test_version_comparison(smaller, larger):
+    assert smaller < larger
Repository: mit-ll-responsible-ai/hydra-zen
Pull request #418 (2023-02-27 14:04:37)

Add type conversion support for `InitVar`
Given:

```python
from dataclasses import dataclass, InitVar
from inspect import signature

from hydra_zen import builds

@dataclass
class A:
    x: InitVar[int]

Conf = builds(A, populate_full_signature=True)
```

Before:

```python
>>> signature(Conf)
<Signature (x: Any) -> None>
```

After:

```python
>>> signature(Conf)
<Signature (x: int) -> None>
```



Patch:
diff --git a/src/hydra_zen/structured_configs/_utils.py b/src/hydra_zen/structured_configs/_utils.py
index d91d8efa..8d5ece56 100644
--- a/src/hydra_zen/structured_configs/_utils.py
+++ b/src/hydra_zen/structured_configs/_utils.py
@@ -3,7 +3,7 @@
 import inspect
 import sys
 import warnings
-from dataclasses import MISSING, field as _field, is_dataclass
+from dataclasses import MISSING, InitVar, field as _field, is_dataclass
 from enum import Enum
 from keyword import iskeyword
 from pathlib import Path
@@ -455,6 +455,13 @@ def sanitized_type(
         # these aren't hashable -- can't check for membership in set
         return Any
 
+    if isinstance(type_, InitVar):
+        return sanitized_type(
+            type_.type,
+            primitive_only=primitive_only,
+            wrap_optional=wrap_optional,
+            nested=nested,
+        )
     if (
         type_ is Any
         or type_ in _supported_types


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index d4212024..b21e64b4 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -5,7 +5,7 @@ import enum
 import random
 import string
 import sys
-from dataclasses import dataclass, field as dataclass_field, make_dataclass
+from dataclasses import InitVar, dataclass, field as dataclass_field, make_dataclass
 from inspect import signature
 from pathlib import Path, PosixPath, WindowsPath
 from typing import (
@@ -273,6 +273,7 @@ vDict = Dict[Any, Any] if sys.version_info < (3, 8) else Dict
         ),
         (Tuple[Tuple[int, ...], ...], Tuple[Any, ...]),
         (Optional[Tuple[Tuple[int, ...], ...]], Optional[Tuple[Any, ...]]),
+        (InitVar[List[frozenset]], Any if sys.version_info < (3, 8) else List[Any]),
     ],
 )
 def test_sanitized_type_expected_behavior(in_type, expected_type):