Skip to content

Commit

Permalink
Improve typings
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Sep 4, 2021
1 parent 4f81f4b commit 67031eb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
36 changes: 17 additions & 19 deletions strawberry/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def field(
provides: Optional[List[str]] = None,
requires: Optional[List[str]] = None,
external: bool = False,
init: Optional[Literal[True]] = True,
permission_classes: Optional[List[Type[BasePermission]]] = None,
deprecation_reason: Optional[str] = None,
default: Any = UNSET,
Expand Down Expand Up @@ -107,27 +108,24 @@ def field(


def field(
resolver: Optional[_RESOLVER_TYPE] = None,
resolver=None,
*,
name: Optional[str] = None,
is_subscription: bool = False,
description: Optional[str] = None,
provides: Optional[List[str]] = None,
requires: Optional[List[str]] = None,
external: bool = False,
init: Optional[bool] = False,
permission_classes: Optional[List[Type[BasePermission]]] = None,
deprecation_reason: Optional[str] = None,
default: Any = UNSET,
default_factory: Union[Callable, object] = UNSET,
name=None,
is_subscription=False,
description=None,
provides=None,
requires=None,
external=False,
permission_classes=None,
deprecation_reason=None,
default=UNSET,
default_factory=UNSET,
# This init parameter is used by PyRight to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init=None,
) -> Any:
# hack to prevent mypy from complaining about:
# `Not all union combinations were tried because there are too many unions`
# without using # type: ignore on multiple lines
def _inner(**kwargs):
return base_field(**kwargs)

return _inner(
return base_field(
resolver=resolver,
name=name,
is_subscription=is_subscription,
Expand Down
26 changes: 15 additions & 11 deletions strawberry/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def field(
name: Optional[str] = None,
is_subscription: bool = False,
description: Optional[str] = None,
init: Optional[Literal[True]] = True,
permission_classes: Optional[List[Type[BasePermission]]] = None,
federation: Optional[FederationFieldParams] = None,
deprecation_reason: Optional[str] = None,
Expand All @@ -321,17 +322,20 @@ def field(


def field(
resolver: Optional[_RESOLVER_TYPE] = None,
resolver=None,
*,
name: Optional[str] = None,
is_subscription: bool = False,
description: Optional[str] = None,
init: Optional[bool] = False,
permission_classes: Optional[List[Type[BasePermission]]] = None,
federation: Optional[FederationFieldParams] = None,
deprecation_reason: Optional[str] = None,
default: Any = UNSET,
default_factory: Union[Callable, object] = UNSET,
name=None,
is_subscription=False,
description=None,
permission_classes=None,
federation=None,
deprecation_reason=None,
default=UNSET,
default_factory=UNSET,
# This init parameter is used by PyRight to determine whether this field
# is added in the constructor or not. It is not used to change
# any behavior at the moment.
init=None,
) -> Any:
"""Annotates a method or property as a GraphQL field.
Expand Down Expand Up @@ -362,7 +366,7 @@ def field(
)

if resolver:
assert init is False, "Can't set init as True when passing a resolver."
assert init is not True, "Can't set init as True when passing a resolver."
return field_(resolver)
return field_

Expand Down

0 comments on commit 67031eb

Please sign in to comment.