Skip to content

Commit

Permalink
adopt black 2023 stable style
Browse files Browse the repository at this point in the history
  • Loading branch information
rsokl committed Feb 1, 2023
1 parent c04ee87 commit 312e181
Show file tree
Hide file tree
Showing 24 changed files with 8 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
Expand Down
2 changes: 1 addition & 1 deletion src/hydra_zen/_hydra_overloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def instantiate(
List[Any],
],
*args: Any,
**kwargs: Any
**kwargs: Any,
) -> Any:
...

Expand Down
3 changes: 1 addition & 2 deletions src/hydra_zen/_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,8 @@ def launch(
{}
if (not SUPPORTS_VERSION_BASE or version_base is _NotSet)
else {"version_base": version_base}
)
),
):

# taken from hydra.compose with support for MULTIRUN
gh = GlobalHydra.instance()
assert gh.hydra is not None
Expand Down
1 change: 0 additions & 1 deletion src/hydra_zen/_utils/coerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@


def _is_namedtuple_type(x) -> TypeGuard[Type[NamedTuple]]: # pragma: no cover

try:
bases = x.__bases__
fields = x._fields
Expand Down
4 changes: 0 additions & 4 deletions src/hydra_zen/structured_configs/_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ def hydrated_dataclass(
"""

def wrapper(decorated_obj: Any) -> Any:

if not isinstance(decorated_obj, type):
raise NotImplementedError(
"Class instances are not supported by `hydrated_dataclass`."
Expand Down Expand Up @@ -787,7 +786,6 @@ def sanitized_field(
_mutable_default_permitted: bool = True,
convert_dataclass: bool,
) -> Field[Any]:

value = sanitized_default_value(
value,
allow_zen_conversion=allow_zen_conversion,
Expand Down Expand Up @@ -1926,7 +1924,6 @@ def builds(target, populate_full_signature=False, **kw):
# resulting dataclass will simply be inherited from and extended.
# The issues we catch here cannot be fixed downstream.
if target_has_valid_signature:

if not sig_by_kind[_VAR_KEYWORD]:
# check for unexpected kwargs
if not set(kwargs_for_target) <= nameable_params_in_sig:
Expand Down Expand Up @@ -2147,7 +2144,6 @@ def builds(target, populate_full_signature=False, **kw):
and builds_bases
and value.default_factory is not MISSING
): # pragma: no cover

# Addresses omegaconf #830 https://github.com/omry/omegaconf/issues/830
#
# Value was passed as a field-with-default-factory, we'll
Expand Down
4 changes: 0 additions & 4 deletions src/hydra_zen/structured_configs/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ def get_obj_path(obj: Any) -> str:
if not is_classmethod(obj):
return f"{module}.{name}"
else:

# __qualname__ reflects name of class that originally defines classmethod.
# Does not point to child in case of inheritance.
#
Expand Down Expand Up @@ -358,7 +357,6 @@ def sanitized_type(
no_nested_container = not HYDRA_SUPPORTS_NESTED_CONTAINER_TYPES

if origin is not None:

# Support for Annotated[x, y]
# Python 3.9+
# # type_: Annotated[x, y]; origin -> Annotated; args -> (x, y)
Expand Down Expand Up @@ -463,7 +461,6 @@ def sanitized_type(
or is_dataclass(type_)
or (isinstance(type_, type) and issubclass(type_, Enum))
):

if sys.version_info[:2] == (3, 6) and type_ is Dict: # pragma: no cover
type_ = Dict[Any, Any]

Expand Down Expand Up @@ -539,7 +536,6 @@ def valid_defaults_list(hydra_defaults: Any) -> bool:

has_self = False
for item in hydra_defaults:

if item == "_self_":
if not has_self:
has_self = True
Expand Down
1 change: 0 additions & 1 deletion src/hydra_zen/typing/_builds_overloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@


class StdBuilds(Protocol):

# partial=False, pop-sig=True; no *args, **kwargs, nor builds_bases
@overload
def __call__(
Expand Down
11 changes: 4 additions & 7 deletions tests/annotations/declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,8 @@ def caller(
dataclass_name: Optional[str],
fbuilds: FullBuilds = ...,
pbuilds: PBuilds = ...,
**kwargs_for_target: SupportedPrimitive
**kwargs_for_target: SupportedPrimitive,
):

bout = builds(
int,
zen_partial=zen_partial,
Expand All @@ -825,7 +824,7 @@ def caller(
frozen=frozen,
builds_bases=builds_bases,
dataclass_name=dataclass_name,
**kwargs_for_target
**kwargs_for_target,
)

reveal_type(
Expand All @@ -844,7 +843,7 @@ def caller(
frozen=frozen,
builds_bases=builds_bases,
dataclass_name=dataclass_name,
**kwargs_for_target
**kwargs_for_target,
)

reveal_type(
Expand All @@ -863,7 +862,7 @@ def caller(
frozen=frozen,
builds_bases=builds_bases,
dataclass_name=dataclass_name,
**kwargs_for_target
**kwargs_for_target,
)

reveal_type(
Expand Down Expand Up @@ -944,7 +943,6 @@ def f(x: int):


def check_make_custom_builds_overloads(boolean: bool, optional_boolean: Optional[bool]):

# partial = False, pop-sig = False
reveal_type(make_custom_builds_fn(zen_partial=False), expected_text="StdBuilds")

Expand Down Expand Up @@ -1010,7 +1008,6 @@ def check_instantiate_overrides(
def check_hydra_defaults(
partial_builds: PBuilds, full_builds: FullBuilds, std_builds: StdBuilds
):

builds(int, hydra_defaults=["_self_", {"a": "b"}])
partial_builds(int, hydra_defaults=["_self_", {"a": "b"}])
full_builds(int, hydra_defaults=["_self_", {"a": "b"}])
Expand Down
1 change: 0 additions & 1 deletion tests/custom_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def valid_builds_args(*required: str, excluded: Sequence[str] = ()):

@st.composite
def _partition(draw: st.DrawFn, collection: T, ordered: bool) -> Tuple[T, T]:

if isinstance(collection, dict):
keys = list(collection)
else:
Expand Down
1 change: 0 additions & 1 deletion tests/pyright_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ def pyright_analyze(
with chdir():
cwd = Path.cwd()
if source is not None:

file_ = cwd / "source.py"
file_.write_text(source, encoding="utf-8")
else:
Expand Down
1 change: 0 additions & 1 deletion tests/test_compatibility/test_hydra_supports_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_HydraPartialBuilds_protocol():


def test_HYDRA_SUPPORTS_PARTIAL_is_set_properly():

obj = instantiate(HydraPartialConf)
if HYDRA_SUPPORTS_PARTIAL:
# instantiation should produce `functools.partial(dict, x=1)`
Expand Down
1 change: 0 additions & 1 deletion tests/test_compatibility/test_omegaconf_830.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def test_known_inheritance_issues_in_omegaconf_are_circumvented(
not PATCH_OMEGACONF_830, reason="issue has been patched by omegaconf"
)
def test_hydrated_dataclass_raises_on_omegaconf_inheritance_issue():

Parent = make_config(x=1)

with pytest.raises(HydraZenValidationError):
Expand Down
2 changes: 0 additions & 2 deletions tests/test_compatibility/test_primitive_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class C_paths:


def test_hydra_supports_bytes():

if HYDRA_SUPPORTS_BYTES:
OmegaConf.create(C_bytes) # type: ignore
else:
Expand All @@ -34,7 +33,6 @@ def test_hydra_supports_bytes():


def test_hydra_supports_paths():

if HYDRA_SUPPORTS_Path:
out = OmegaConf.create(C_paths) # type: ignore
assert isinstance(out.x, Path)
Expand Down
5 changes: 0 additions & 5 deletions tests/test_dataclass_semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def f(x, y, z: int = 3):

@given(full_sig=st.booleans(), partial=st.none() | st.booleans())
def test_builds_produces_dataclass(full_sig: bool, partial: bool):

if full_sig and not partial:
Builds_f = builds(f, populate_full_signature=full_sig, zen_partial=partial)
else:
Expand All @@ -54,7 +53,6 @@ def f_2(x, y, z):
@pytest.mark.parametrize("full_sig", [True, False])
@pytest.mark.parametrize("partial", [True, False, None])
def test_chain_builds_of_targets_with_common_interfaces(full_sig, partial: bool):

# Note that conf_1 and conf_2 target `f` whereas conf_3 targets `f_three_vars`,
# which have identical interfaces.
conf_1 = builds(f_2, x=1)
Expand All @@ -81,7 +79,6 @@ def test_chain_builds_of_targets_with_common_interfaces(full_sig, partial: bool)
@pytest.mark.parametrize("full_sig", [True, False])
@pytest.mark.parametrize("partial", [True, False, None])
def test_pos_args_with_inheritance(full_sig, partial: bool):

conf_1 = builds(f_three_vars, 1, 2)
conf_2 = builds(
f_three_vars,
Expand Down Expand Up @@ -123,7 +120,6 @@ class FrozenHydrated:
],
)
def test_frozen_via_builds(fn):

conf_f = fn()

with pytest.raises(FrozenInstanceError):
Expand Down Expand Up @@ -349,7 +345,6 @@ def test_namespace(fn):
],
)
def test_kwonly(kw_only: bool, fn):

Conf = fn(zen_dataclass={"kw_only": kw_only})

if sys.version_info < (3, 10):
Expand Down
1 change: 0 additions & 1 deletion tests/test_hydra_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def test_hydra_convert(
kwargs = dict(hydra_convert=convert) if convert is not NotSet else {}

if not via_hydrated_dataclass:

out = instantiate(
builds(
f_for_convert,
Expand Down
1 change: 0 additions & 1 deletion tests/test_make_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def test_types_are_sanitized(hint):


def test_type_broadening_for_builds_default():

instantiate(make_config(a=ZenField(hint=int, default=builds(int))))

with pytest.raises(OmegaConfBaseException):
Expand Down
2 changes: 0 additions & 2 deletions tests/test_signature_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def f1(x=2):
def test_user_specified_value_overrides_default(
user_value, as_hydrated_dataclass: bool, full_signature: bool
):

if not as_hydrated_dataclass:
BuildsF = builds(f1, x=user_value, populate_full_signature=full_signature)
else:
Expand Down Expand Up @@ -149,7 +148,6 @@ def f3(x: str, *args, y: int = 22, z=[2], **kwargs):
def test_builds_with_full_sig_mirrors_target_sig(
include_extra_param: bool, partial: Optional[bool]
):

kwargs = dict(named_param=2) if include_extra_param else {}
kwargs["y"] = 0 # overwrite default value
Conf = builds(f3, populate_full_signature=True, zen_partial=partial, **kwargs)
Expand Down
1 change: 0 additions & 1 deletion tests/test_third_party/test_type_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ def test_signature_parsing(args, kwargs, should_pass, validator, target, as_yaml
hydra_convert="all",
)
if as_yaml:

try:
# omegaconf >= 2.2.0 no longer casts lists to strings
conf_with_val = OmegaConf.create(to_yaml(conf_with_val))
Expand Down
1 change: 0 additions & 1 deletion tests/test_third_party/test_using_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def test_just_on_pydantic_dataclass(config_maker):


def test_pydantic_runtime_type_checking():

Conf = builds(User, populate_full_signature=True, hydra_convert="all")
inst_bad = Conf(id=22, height=-50, age=-100)
with pytest.raises(InstantiationException):
Expand Down
1 change: 0 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ class SomeProtocol(Protocol[T]): # type: ignore
],
)
def test_sanitized_type_expected_behavior(in_type, expected_type):

assert sanitized_type(in_type) == expected_type, in_type

if in_type != expected_type:
Expand Down
1 change: 0 additions & 1 deletion tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def f(y):

@given(partial=st.none() | st.booleans(), full_sig=st.booleans())
def test_builds_raises_when_base_has_invalid_arg(full_sig, partial):

with pytest.raises(TypeError):
builds(
f,
Expand Down
1 change: 0 additions & 1 deletion tests/test_zen.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ def test_pre_call_validates_bad_param_name():
unpack_kw=st.booleans(),
)
def test_zen_call(x: int, y: int, instantiate_cfg, func, unpack_kw):

cfg = make_config(x=x, y=y)
if instantiate_cfg:
cfg = cfg()
Expand Down
2 changes: 0 additions & 2 deletions tests/test_zen_processing/test_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ class ZenFalseHydraFalse:
def test_partial_via_inheritance(
child_partial: bool, zen_meta: dict, parents: Tuple[Type[DataClass_], ...]
):

expected_out = dict(child_field=2)
if parents:
expected_out["a"] = 1
Expand Down Expand Up @@ -251,7 +250,6 @@ def test_partial_via_inheritance(
def test_instantiation_never_produces_partiald_zen_processing(
child_partial: bool, zen_meta: dict, parents: Tuple[Type[DataClass_], ...]
):

Conf = builds(
dict, zen_partial=child_partial, zen_meta=zen_meta, builds_bases=parents
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_zen_processing/test_zen_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_zen_wrappers_expected_behavior(
**kwargs,
zen_wrappers=wrappers,
zen_partial=zen_partial,
zen_meta=zen_meta
zen_meta=zen_meta,
)
if not as_yaml:
instantiated = instantiate(conf)
Expand Down

0 comments on commit 312e181

Please sign in to comment.