Skip to content

Commit

Permalink
fix myp and flake8 issues after deps update
Browse files Browse the repository at this point in the history
  • Loading branch information
m.kindritskiy committed Sep 15, 2024
1 parent e2179a7 commit 63cc321
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 110 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ extend-ignore = E203,E231
ignore =
F811,
W503,
E701,
E704
3 changes: 1 addition & 2 deletions examples/federation-compatibility/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ def resolve_reference_direct(representations):
compose=True,
import_url="https://myspecs.dev/myCustomDirective/v1.0",
)
class Custom(FederationSchemaDirective):
...
class Custom(FederationSchemaDirective): ...


QUERY_GRAPH = Graph(
Expand Down
3 changes: 1 addition & 2 deletions hiku/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@


class Hasher(Protocol):
def update(self, data: bytes) -> None:
...
def update(self, data: bytes) -> None: ...


CacheKeyFn = Callable[["Context", Hasher], None]
Expand Down
13 changes: 4 additions & 9 deletions hiku/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@
import ast as _ast
from typing import Any

# TODO: maybe we can remove this version check
PY38: bool = sys.version_info >= (3, 8)
PY310: bool = sys.version_info >= (3, 10)


# TODO: maybe we can remove this custom class ?
class _AST:
def __getattr__(self, name: str) -> Any:
return getattr(_ast, name)

if PY38:
arguments = _ast.arguments
else:

@staticmethod
def arguments(_, args, vararg, kwonlyargs, kw_defaults, kwarg, defaults): # type: ignore[no-untyped-def] # noqa
return _ast.arguments(
args, vararg, kwonlyargs, kw_defaults, kwarg, defaults
) # noqa
arguments = _ast.arguments


ast = _AST()
Expand All @@ -28,6 +22,7 @@ def arguments(_, args, vararg, kwonlyargs, kw_defaults, kwarg, defaults): # typ
else:
from typing_extensions import Concatenate, ParamSpec, TypeAlias

# TODO: maybe we can remove this custom class ?
if sys.version_info >= (3, 8):
from typing import Protocol
else:
Expand Down
12 changes: 4 additions & 8 deletions hiku/endpoint/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,12 @@ class GraphQLEndpoint(BaseSyncGraphQLEndpoint):
@overload
def dispatch(
self, data: GraphQLRequest, context: Optional[Dict] = None
) -> GraphQLResponse:
...
) -> GraphQLResponse: ...

@overload
def dispatch(
self, data: BatchedRequest, context: Optional[Dict] = None
) -> BatchedResponse:
...
) -> BatchedResponse: ...

def dispatch(
self, data: SingleOrBatchedRequest, context: Optional[Dict] = None
Expand Down Expand Up @@ -147,14 +145,12 @@ class AsyncGraphQLEndpoint(BaseAsyncGraphQLEndpoint):
@overload
async def dispatch(
self, data: GraphQLRequest, context: Optional[Dict] = None
) -> GraphQLResponse:
...
) -> GraphQLResponse: ...

@overload
async def dispatch(
self, data: BatchedRequest, context: Optional[Dict] = None
) -> BatchedResponse:
...
) -> BatchedResponse: ...

async def dispatch(
self, data: SingleOrBatchedRequest, context: Optional[Dict] = None
Expand Down
6 changes: 2 additions & 4 deletions hiku/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,15 +1052,13 @@ def _prepare_workflow(
async def execute(
self: "Engine[BaseAsyncExecutor]",
execution_context: ExecutionContext,
) -> Proxy:
...
) -> Proxy: ...

@overload
def execute(
self: "Engine[BaseSyncExecutor]",
execution_context: ExecutionContext,
) -> Proxy:
...
) -> Proxy: ...

def execute(
self,
Expand Down
9 changes: 4 additions & 5 deletions hiku/executors/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@


class SubmitRes(Protocol):
def result(self) -> Any:
...
def result(self) -> Any: ...


class Workflow:
Expand Down Expand Up @@ -67,9 +66,9 @@ def __init__(self, executor: BaseExecutor) -> None:
"""
A dictionary of callbacks associated with each future or task set.
"""
self._callbacks: DefaultDict[
Union[SubmitRes, TaskSet], List
] = defaultdict(list)
self._callbacks: DefaultDict[Union[SubmitRes, TaskSet], List] = (
defaultdict(list)
)

@property
def __futures__(self) -> List[SubmitRes]:
Expand Down
5 changes: 3 additions & 2 deletions hiku/executors/sync.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import (
Generic,
TypeVar,
Callable,
TYPE_CHECKING,
Expand All @@ -18,11 +19,11 @@
T = TypeVar("T")


class FutureLike:
class FutureLike(Generic[T]):
def __init__(self, result: T) -> None:
self._result = result

def result(self) -> T: # type: ignore[type-var]
def result(self) -> T:
return self._result


Expand Down
2 changes: 1 addition & 1 deletion hiku/executors/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def submit(self, fn: Callable, *args: Any, **kwargs: Any) -> Future:

def process(self, queue: "Queue", workflow: "Workflow") -> Proxy:
while queue.__futures__:
done, _ = wait( # type: ignore
done, _ = wait(
queue.__futures__, return_when=FIRST_COMPLETED # type: ignore
)
queue.progress(done)
Expand Down
12 changes: 7 additions & 5 deletions hiku/export/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ def visit_link(self, obj: Link) -> ast.FieldNode:
def visit_fragment(self, obj: Fragment) -> Any:
if obj.name is None:
return ast.InlineFragmentNode(
type_condition=ast.NamedTypeNode(
name=_name(obj.type_name),
)
if obj.type_name is not None
else None,
type_condition=(
ast.NamedTypeNode(
name=_name(obj.type_name),
)
if obj.type_name is not None
else None
),
selection_set=self.visit(obj.node),
)

Expand Down
10 changes: 5 additions & 5 deletions hiku/extensions/base_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


class Extension:
def on_init(
def on_init( # type: ignore[return]
self, execution_context: ExecutionContext
) -> AsyncIteratorOrIterator[None]:
"""Called once during schema creation.
Expand All @@ -42,7 +42,7 @@ def on_init(
"""
yield None

def on_operation(
def on_operation( # type: ignore[return]
self, execution_context: ExecutionContext
) -> AsyncIteratorOrIterator[None]:
"""Called before and after the operation step.
Expand All @@ -60,7 +60,7 @@ def on_operation(
"""
yield None

def on_parse(
def on_parse( # type: ignore[return]
self, execution_context: ExecutionContext
) -> AsyncIteratorOrIterator[None]:
"""Called before and after the parsing step.
Expand All @@ -74,7 +74,7 @@ def on_parse(
"""
yield None

def on_validate(
def on_validate( # type: ignore[return]
self, execution_context: ExecutionContext
) -> AsyncIteratorOrIterator[None]:
"""Called before and after the validation step.
Expand All @@ -85,7 +85,7 @@ def on_validate(
"""
yield None

def on_execute(
def on_execute( # type: ignore[return]
self, execution_context: ExecutionContext
) -> AsyncIteratorOrIterator[None]:
"""Called before and after the execution step.
Expand Down
8 changes: 4 additions & 4 deletions hiku/federation/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
T = TypeVar("T", bound="FederationSchemaDirective")


LinkPurpose = Enum("link__Purpose", ["SECURITY", "EXECUTION"])
LinkPurpose = Enum("link__Purpose", ["SECURITY", "EXECUTION"]) # type: ignore[misc] # noqa: E501


@dataclass
Expand Down Expand Up @@ -69,9 +69,9 @@ def _wrap(cls: T) -> T:
args=fields,
description=description,
repeatable=repeatable,
compose_options=ComposeOptions(import_url=import_url)
if compose
else None,
compose_options=(
ComposeOptions(import_url=import_url) if compose else None
),
)

return cls
Expand Down
8 changes: 5 additions & 3 deletions hiku/federation/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ async def wrapper(*args: t.Any, **kwargs: t.Any) -> t.List[t.Tuple]:
return Link(
"_entities",
Sequence[Optional[UnionRef["_Entity"]]],
_asyncify(entities_resolver)
if self.is_async
else entities_resolver,
(
_asyncify(entities_resolver)
if self.is_async
else entities_resolver
),
options=[
Option("representations", Sequence[_Any]),
],
Expand Down
9 changes: 3 additions & 6 deletions hiku/federation/scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ def serialize(cls, value: str) -> Any:


@federation_version([2])
class _Any(_Scalar):
...
class _Any(_Scalar): ...


@federation_version([1, 2])
@scalar(name="_FieldSet")
class FieldSet(_Scalar):
...
class FieldSet(_Scalar): ...


@federation_version([2])
@scalar(name="link__Import")
class LinkImport(_Scalar):
...
class LinkImport(_Scalar): ...
22 changes: 12 additions & 10 deletions hiku/federation/sdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ def _name(value: t.Optional[str]) -> t.Optional[ast.NameNode]:


@t.overload
def coerce_type(x: str) -> ast.NameNode:
...
def coerce_type(x: str) -> ast.NameNode: ...


@t.overload
def coerce_type(x: ast.Node) -> ast.Node:
...
def coerce_type(x: ast.Node) -> ast.Node: ...


def coerce_type(x): # type: ignore[no-untyped-def]
Expand Down Expand Up @@ -447,9 +445,11 @@ def visit_field(self, obj: Field) -> ast.FieldDefinitionNode:
type=_encode_type(obj.type),
arguments=[self.visit(o) for o in obj.options],
directives=[self.visit(d) for d in obj.directives],
description=_encode_default_value(obj.description)
if obj.description
else None,
description=(
_encode_default_value(obj.description)
if obj.description
else None
),
)

def visit_node(
Expand Down Expand Up @@ -484,9 +484,11 @@ def visit_link(self, obj: Link) -> ast.FieldDefinitionNode:
def visit_option(self, obj: Option) -> ast.InputValueDefinitionNode:
return ast.InputValueDefinitionNode(
name=_name(obj.name),
description=_encode_default_value(obj.description)
if obj.description
else None,
description=(
_encode_default_value(obj.description)
if obj.description
else None
),
type=_encode_type(obj.type, input_type=True),
default_value=_encode_default_value(obj.default),
)
Expand Down
15 changes: 6 additions & 9 deletions hiku/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
are used to fetch any data from any data source.
"""

import dataclasses
import typing as t

Expand Down Expand Up @@ -499,8 +500,7 @@ def __init__(
description: t.Optional[str] = None,
directives: t.Optional[t.List[SchemaDirective]] = None,
deprecated: t.Optional[str] = None,
):
...
): ...

@t.overload
def __init__(
Expand All @@ -514,8 +514,7 @@ def __init__(
description: t.Optional[str] = None,
directives: t.Optional[t.List[SchemaDirective]] = None,
deprecated: t.Optional[str] = None,
):
...
): ...

@t.overload
def __init__(
Expand All @@ -529,8 +528,7 @@ def __init__(
description: t.Optional[str] = None,
directives: t.Optional[t.List[SchemaDirective]] = None,
deprecated: t.Optional[str] = None,
):
...
): ...

@t.overload
def __init__(
Expand All @@ -544,8 +542,7 @@ def __init__(
description: t.Optional[str] = None,
directives: t.Optional[t.List[SchemaDirective]] = None,
deprecated: t.Optional[str] = None,
):
...
): ...

def __init__( # type: ignore[no-untyped-def]
self,
Expand Down Expand Up @@ -679,7 +676,7 @@ def __init__(
implements: t.Optional[t.Sequence[str]] = None,
):
"""
:param name: name of the node
:param name: name of the node (None if Root node)
:param fields: list of fields and links
:param description: description of the node
:param directives: list of directives for the node
Expand Down
Loading

0 comments on commit 63cc321

Please sign in to comment.