Skip to content

Commit

Permalink
Merge pull request #764 from mit-ll-responsible-ai/py39-upgrade
Browse files Browse the repository at this point in the history
Upgrade to python 3.9 -- builtin generic containers
  • Loading branch information
rsokl authored Jan 2, 2025
2 parents b66e6e1 + 880efde commit f3f584d
Show file tree
Hide file tree
Showing 37 changed files with 504 additions and 625 deletions.
2 changes: 1 addition & 1 deletion project_tooling/make_rst_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def make_table(*cols: str) -> str:
lines.append(
"| "
+ "| ".join(
(li if li else "") + " " * (longest[n] - len((li if li else "")) + 1)
(li if li else "") + " " * (longest[n] - len(li if li else "") + 1)
for n, li in enumerate(ll)
)
+ "|"
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ description = "Configurable, reproducible, and scalable workflows in Python, via
readme = "README.md"
requires-python = ">=3.9"
dependencies = ["hydra-core >= 1.2.0",
"omegaconf >= 2.2.1",
"omegaconf >= 2.2.3",
"typing-extensions >= 4.1.0, !=4.6.0",
]
license = { text = "MIT" }
Expand Down Expand Up @@ -158,7 +158,7 @@ commands = pytest tests/ {posargs: -n auto --maxprocesses=4}
[testenv:min-deps]
description = Runs test suite against minimum supported versions of dependencies.
deps = hydra-core==1.2.0
omegaconf==2.2.1
omegaconf==2.2.3
typing-extensions==4.1.0
{[testenv]deps}
importlib-resources<6.2.0
Expand Down
5 changes: 2 additions & 3 deletions src/hydra_zen/_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from enum import Enum
from functools import partial
from pathlib import Path, PosixPath, WindowsPath
from typing import FrozenSet, NamedTuple
from typing import Final, NamedTuple

import hydra
import omegaconf
from typing_extensions import Final

NoneType = type(None)

Expand Down Expand Up @@ -59,7 +58,7 @@ def _get_version(ver_str: str) -> Version:
WindowsPath,
}
)
ZEN_SUPPORTED_PRIMITIVES: FrozenSet[type] = frozenset(
ZEN_SUPPORTED_PRIMITIVES: frozenset[type] = frozenset(
{
set,
frozenset,
Expand Down
24 changes: 6 additions & 18 deletions src/hydra_zen/_hydra_overloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,7 @@
import pathlib
from dataclasses import is_dataclass
from functools import partial, wraps
from typing import (
IO,
Any,
Callable,
Dict,
List,
Tuple,
Type,
TypeVar,
Union,
cast,
overload,
)
from typing import IO, Any, Callable, TypeVar, Union, cast, overload

from hydra.utils import instantiate as hydra_instantiate
from omegaconf import MISSING, DictConfig, ListConfig, OmegaConf
Expand All @@ -59,8 +47,8 @@
def _call_target(
_target_: F,
_partial_: bool,
args: Tuple[Any, ...],
kwargs: Dict[str, Any],
args: tuple[Any, ...],
kwargs: dict[str, Any],
full_key: str,
*,
target_wrapper: Callable[[F], F],
Expand Down Expand Up @@ -190,9 +178,9 @@ def instantiate(
ListConfig,
DictConfig,
DataClass_,
Type[DataClass_],
Dict[Any, Any],
List[Any],
type[DataClass_],
dict[Any, Any],
list[Any],
],
*args: Any,
_target_wrapper_: Union[Callable[[F], F], None] = ...,
Expand Down
30 changes: 11 additions & 19 deletions src/hydra_zen/_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
# SPDX-License-Identifier: MIT
import warnings
from collections import UserList
from collections.abc import Mapping
from dataclasses import fields, is_dataclass
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Generic,
List,
Mapping,
Optional,
Tuple,
Type,
TypeVar,
Union,
cast,
Expand All @@ -34,7 +30,7 @@
from hydra_zen.typing._implementations import DataClass_, InstOrType

T = TypeVar("T", bound=Any)
HydraPrimitives: TypeAlias = Union[None, int, float, bool, str, Dict[str, str]]
HydraPrimitives: TypeAlias = Union[None, int, float, bool, str, dict[str, str]]

if TYPE_CHECKING: # pragma: no cover
# branching needed to deal with pyright type-completeness complaints
Expand All @@ -54,17 +50,13 @@ class hydra_list(TUserList, Generic[T1]):
"""Signals that a sequence is provided as a single configured value (i.e. it is not
to be iterated over during a multirun)"""

pass


T2 = TypeVar("T2", bound=Union[HydraPrimitives, hydra_list[HydraPrimitives]])


class multirun(TUserList, Generic[T2]):
"""Signals that a sequence is to be iterated over in a multirun"""

pass


def _safe_name(x: Any) -> str:
return getattr(x, "__name__", str(x))
Expand All @@ -73,7 +65,7 @@ def _safe_name(x: Any) -> str:
def value_check(
name: str,
value: T,
type_: Union[type, Tuple[type, ...]],
type_: Union[type, tuple[type, ...]],
) -> T:
"""
For internal use only.
Expand Down Expand Up @@ -108,7 +100,7 @@ def value_check(
OverrideDict: TypeAlias = Mapping[str, OverrideValues]


def _process_dict_overrides(overrides: OverrideDict) -> List[str]:
def _process_dict_overrides(overrides: OverrideDict) -> list[str]:
"""Convert dict overrides to a list of Hydra CLI compatible args"""
launch_overrides = []
for k, v in overrides.items():
Expand All @@ -128,7 +120,7 @@ def _process_dict_overrides(overrides: OverrideDict) -> List[str]:


def _store_config(
cfg: Union[DataClass_, Type[DataClass_], DictConfig, ListConfig, Mapping[Any, Any]],
cfg: Union[DataClass_, type[DataClass_], DictConfig, ListConfig, Mapping[Any, Any]],
config_name: str = "hydra_launch",
) -> str:
"""Stores configuration object in Hydra's ConfigStore.
Expand Down Expand Up @@ -164,9 +156,9 @@ def _store_config(
def launch(
config: Union[InstOrType[DataClass_], Mapping[str, Any]],
task_function: Callable[[Any], Any],
overrides: Optional[Union[OverrideDict, List[str]]] = ...,
overrides: Optional[Union[OverrideDict, list[str]]] = ...,
multirun: Literal[False] = ...,
version_base: Optional[Union[str, Type[_NotSet]]] = ...,
version_base: Optional[Union[str, type[_NotSet]]] = ...,
to_dictconfig: bool = ...,
config_name: str = ...,
job_name: str = ...,
Expand All @@ -179,9 +171,9 @@ def launch(
def launch(
config: Union[InstOrType[DataClass_], Mapping[str, Any]],
task_function: Callable[[Any], Any],
overrides: Optional[Union[OverrideDict, List[str]]] = ...,
overrides: Optional[Union[OverrideDict, list[str]]] = ...,
multirun: Literal[True] = ...,
version_base: Optional[Union[str, Type[_NotSet]]] = ...,
version_base: Optional[Union[str, type[_NotSet]]] = ...,
to_dictconfig: bool = ...,
config_name: str = ...,
job_name: str = ...,
Expand All @@ -193,9 +185,9 @@ def launch(
def launch(
config: Union[InstOrType[DataClass_], Mapping[str, Any]],
task_function: Callable[[Any], Any],
overrides: Optional[Union[OverrideDict, List[str]]] = None,
overrides: Optional[Union[OverrideDict, list[str]]] = None,
multirun: bool = False,
version_base: Optional[Union[str, Type[_NotSet]]] = _NotSet,
version_base: Optional[Union[str, type[_NotSet]]] = _NotSet,
to_dictconfig: bool = False,
config_name: str = "zen_launch",
job_name: str = "zen_launch",
Expand Down
5 changes: 2 additions & 3 deletions src/hydra_zen/_utils/coerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

import inspect
from collections import deque
from collections.abc import Sequence
from functools import wraps
from typing import (
Callable,
NamedTuple,
Sequence,
Type,
TypeVar,
Union,
cast,
Expand All @@ -25,7 +24,7 @@
__all__ = ["coerce_sequences"]


def _is_namedtuple_type(x) -> TypeGuard[Type[NamedTuple]]: # pragma: no cover
def _is_namedtuple_type(x) -> TypeGuard[type[NamedTuple]]: # pragma: no cover
try:
bases = x.__bases__
fields = x._fields
Expand Down
6 changes: 2 additions & 4 deletions src/hydra_zen/structured_configs/_globals.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Copyright (c) 2025 Massachusetts Institute of Technology
# SPDX-License-Identifier: MIT
# pyright: strict
from typing import FrozenSet

from typing_extensions import Final
from typing import Final

from hydra_zen.funcs import zen_processing

Expand All @@ -24,7 +22,7 @@
]


HYDRA_FIELD_NAMES: FrozenSet[str] = frozenset(_names)
HYDRA_FIELD_NAMES: frozenset[str] = frozenset(_names)

del _names

Expand Down
Loading

0 comments on commit f3f584d

Please sign in to comment.