Skip to content

Commit

Permalink
Merge pull request #632 from mit-ll-responsible-ai/pyright-1p1p347
Browse files Browse the repository at this point in the history
Pyright 1p1p347
  • Loading branch information
rsokl authored Jan 21, 2024
2 parents 3278e7c + 8aa4b06 commit d22c6c5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion deps/requirements-pyright.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pyright==1.1.345
pyright==1.1.347
11 changes: 6 additions & 5 deletions src/hydra_zen/structured_configs/_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def _sanitized_type(
if optional_type is Any: # Union[Any, T] is just Any
return Any

return Union[optional_type, NoneType]
return cast(type, Union[optional_type, NoneType])

if origin is list or origin is List:
if args:
Expand Down Expand Up @@ -2276,7 +2276,8 @@ def builds(self,target, populate_full_signature=False, **kw):
" You can manually create a dataclass to utilize this name in a structured config."
)

target_field: List[Union[Tuple[str, Type[Any]], Tuple[str, Type[Any], Any]]]
# list[tuple[str, type] | tuple[str, type, Any]]
target_field: List[Union[Tuple[str, Any], Tuple[str, Any, Any]]]

# zen_partial behavior:
#
Expand Down Expand Up @@ -2406,7 +2407,7 @@ def builds(self,target, populate_full_signature=False, **kw):
ZEN_WRAPPERS_FIELD_NAME,
Union[
Union[str, Builds[Any]],
Tuple[Union[str, Builds[Any]], ...],
Tuple[Union[str, Builds[Any]], Any],
],
_utils.field(default=validated_wrappers[0], init=False),
),
Expand All @@ -2417,7 +2418,7 @@ def builds(self,target, populate_full_signature=False, **kw):
ZEN_WRAPPERS_FIELD_NAME,
Union[
Union[str, Builds[Any]],
Tuple[Union[str, Builds[Any]], ...],
Tuple[Union[str, Builds[Any]], Any],
],
_utils.field(default=validated_wrappers, init=False),
),
Expand Down Expand Up @@ -3542,7 +3543,7 @@ def get_target(obj: Union[HasTarget, HasTargetInst]) -> Any:
... class A:
... _target_: str = "builtins.dict"
>>> get_target(A)
>>> get_target(A())
<class 'dict'>
and for configs loaded from yamls.
Expand Down
4 changes: 2 additions & 2 deletions src/hydra_zen/structured_configs/_type_guards.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from hydra_zen.funcs import get_obj, zen_processing
from hydra_zen.structured_configs._utils import safe_name
from hydra_zen.typing import Builds, Just, PartialBuilds
from hydra_zen.typing._implementations import DataClass_, HasTarget
from hydra_zen.typing._implementations import DataClass_, HasTarget, HasTargetInst

from ._globals import (
JUST_FIELD_NAME,
Expand Down Expand Up @@ -66,7 +66,7 @@ def safe_getattr(obj: Any, field: str, *default: Any) -> Any:
return getattr(obj, field, *default)


def _get_target(x: HasTarget) -> Any:
def _get_target(x: Union[HasTarget, HasTargetInst]) -> Any:
return safe_getattr(x, TARGET_FIELD_NAME)


Expand Down
4 changes: 3 additions & 1 deletion src/hydra_zen/typing/_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ class MyBuilds(BuildsFn[CustomConfigType[MyType]]):


DefaultsList = List[
Union[str, DataClass_, Mapping[str, Union[None, str, Sequence[str]]]]
Union[
str, DataClass_, Type[DataClass_], Mapping[str, Union[None, str, Sequence[str]]]
]
]


Expand Down
1 change: 0 additions & 1 deletion tests/annotations/declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ class AnEnum(Enum):

def check_zen_field():
ZenField(int)
ZenField(Callable[..., Any])
ZenField(List[int])

ZenField(1.0) # type: ignore
Expand Down

0 comments on commit d22c6c5

Please sign in to comment.