Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type annotations #244

Merged
merged 20 commits into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
restore-keys: |
${{ runner.os }}-node-
- name: Install pyright
run: sudo npm install -g pyright@">1.1.219"
run: sudo npm install -g pyright@">1.1.228"
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tox_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
restore-keys: |
${{ runner.os }}-node-
- name: Install pyright
run: sudo npm install -g pyright@">1.1.219"
run: sudo npm install -g pyright@">1.1.228"
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v2
Expand Down
62 changes: 7 additions & 55 deletions src/hydra_zen/_hydra_overloads.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright (c) 2022 Massachusetts Institute of Technology
# SPDX-License-Identifier: MIT

"""
Provides annotation overloads for various hydra functions, using the types defined in `hydra_zen.typing`.
This enables tools like IDEs to be more incisive during static analysis and to provide users with additional
Expand All @@ -19,14 +18,16 @@

"""

# pyright: strict

import pathlib
from typing import IO, Any, Callable, Type, TypeVar, Union, overload

from hydra.utils import instantiate as hydra_instantiate
from omegaconf import MISSING, DictConfig, ListConfig, OmegaConf

from .typing import Builds, Just, Partial, PartialBuilds
from .typing._implementations import DataClass_, HasTarget, HydraPartialBuilds
from .typing import Builds, Just, Partial
from .typing._implementations import DataClass_, HasTarget, InstOrType, IsPartial

__all__ = ["instantiate", "to_yaml", "save_as_yaml", "load_from_yaml", "MISSING"]

Expand All @@ -36,70 +37,21 @@

@overload
def instantiate(
config: Union[Just[T], Type[Just[T]]], *args: Any, **kwargs: Any
config: InstOrType[Just[T]], *args: Any, **kwargs: Any
) -> T: # pragma: no cover
...


@overload
def instantiate(
config: Union[
HydraPartialBuilds[Callable[..., T]], Type[HydraPartialBuilds[Callable[..., T]]]
],
*args: Any,
**kwargs: Any
) -> Partial[T]: # pragma: no cover
...


@overload
def instantiate(
config: Union[HydraPartialBuilds[Type[T]], Type[HydraPartialBuilds[Type[T]]]],
*args: Any,
**kwargs: Any
) -> Partial[T]: # pragma: no cover
...


@overload
def instantiate(
config: Union[
PartialBuilds[Callable[..., T]], Type[PartialBuilds[Callable[..., T]]]
],
*args: Any,
**kwargs: Any
) -> Partial[T]: # pragma: no cover
...


@overload
def instantiate(
config: Union[PartialBuilds[Type[T]], Type[PartialBuilds[Type[T]]]],
*args: Any,
**kwargs: Any
config: InstOrType[IsPartial[Callable[..., T]]], *args: Any, **kwargs: Any
) -> Partial[T]: # pragma: no cover
...


@overload
def instantiate(
config: Union[Builds[Callable[..., T]], Type[Builds[Callable[..., T]]]],
*args: Any,
**kwargs: Any
) -> T: # pragma: no cover
...


@overload
def instantiate(
config: Callable[..., Builds[Type[T]]], *args: Any, **kwargs: Any
) -> T: # pragma: no cover
...


@overload
def instantiate(
config: Union[Builds[Type[T]], Type[Builds[Type[T]]]], *args: Any, **kwargs: Any
config: InstOrType[Builds[Callable[..., T]]], *args: Any, **kwargs: Any
) -> T: # pragma: no cover
...

Expand Down
2 changes: 1 addition & 1 deletion src/hydra_zen/structured_configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
hydrated_dataclass,
just,
make_config,
make_custom_builds_fn,
mutable_value,
)
from ._make_custom_builds import make_custom_builds_fn

__all__ = [
"builds",
Expand Down
Loading