diff --git a/.flake8 b/.flake8 index 1609f680..f918f55a 100644 --- a/.flake8 +++ b/.flake8 @@ -5,3 +5,5 @@ extend-ignore = E203,E231 ignore = F811, W503, + E701, + E704 diff --git a/examples/federation-compatibility/server.py b/examples/federation-compatibility/server.py index 669a993a..07cd9927 100644 --- a/examples/federation-compatibility/server.py +++ b/examples/federation-compatibility/server.py @@ -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( diff --git a/hiku/cache.py b/hiku/cache.py index c01d916b..02e0ff45 100644 --- a/hiku/cache.py +++ b/hiku/cache.py @@ -55,8 +55,7 @@ class Hasher(Protocol): - def update(self, data: bytes) -> None: - ... + def update(self, data: bytes) -> None: ... CacheKeyFn = Callable[["Context", Hasher], None] diff --git a/hiku/compat.py b/hiku/compat.py index 639f51b2..77930730 100644 --- a/hiku/compat.py +++ b/hiku/compat.py @@ -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() @@ -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: diff --git a/hiku/endpoint/graphql.py b/hiku/endpoint/graphql.py index 761f577c..318ff83e 100644 --- a/hiku/endpoint/graphql.py +++ b/hiku/endpoint/graphql.py @@ -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 @@ -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 diff --git a/hiku/engine.py b/hiku/engine.py index 4363e09d..ec7853c2 100644 --- a/hiku/engine.py +++ b/hiku/engine.py @@ -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, diff --git a/hiku/executors/queue.py b/hiku/executors/queue.py index c5987342..4f48a0f8 100644 --- a/hiku/executors/queue.py +++ b/hiku/executors/queue.py @@ -18,8 +18,7 @@ class SubmitRes(Protocol): - def result(self) -> Any: - ... + def result(self) -> Any: ... class Workflow: @@ -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]: diff --git a/hiku/executors/sync.py b/hiku/executors/sync.py index 54a02099..98d981d9 100644 --- a/hiku/executors/sync.py +++ b/hiku/executors/sync.py @@ -1,4 +1,5 @@ from typing import ( + Generic, TypeVar, Callable, TYPE_CHECKING, @@ -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 diff --git a/hiku/executors/threads.py b/hiku/executors/threads.py index 2fa88a7b..8a9278bd 100644 --- a/hiku/executors/threads.py +++ b/hiku/executors/threads.py @@ -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) diff --git a/hiku/export/graphql.py b/hiku/export/graphql.py index 4eafd3c4..879c5037 100644 --- a/hiku/export/graphql.py +++ b/hiku/export/graphql.py @@ -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), ) diff --git a/hiku/extensions/base_extension.py b/hiku/extensions/base_extension.py index 5f189528..0f85b61f 100644 --- a/hiku/extensions/base_extension.py +++ b/hiku/extensions/base_extension.py @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/hiku/federation/directive.py b/hiku/federation/directive.py index 2a23574e..6ae6745b 100644 --- a/hiku/federation/directive.py +++ b/hiku/federation/directive.py @@ -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 @@ -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 diff --git a/hiku/federation/graph.py b/hiku/federation/graph.py index ffcfd530..212ef575 100644 --- a/hiku/federation/graph.py +++ b/hiku/federation/graph.py @@ -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]), ], diff --git a/hiku/federation/scalars.py b/hiku/federation/scalars.py index b1f7c99b..cfe7d3f5 100644 --- a/hiku/federation/scalars.py +++ b/hiku/federation/scalars.py @@ -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): ... diff --git a/hiku/federation/sdl.py b/hiku/federation/sdl.py index b6752f9c..4952f44a 100644 --- a/hiku/federation/sdl.py +++ b/hiku/federation/sdl.py @@ -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] @@ -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( @@ -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), ) diff --git a/hiku/graph.py b/hiku/graph.py index 31c0f56e..691da906 100644 --- a/hiku/graph.py +++ b/hiku/graph.py @@ -6,6 +6,7 @@ are used to fetch any data from any data source. """ + import dataclasses import typing as t @@ -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__( @@ -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__( @@ -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__( @@ -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, @@ -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 diff --git a/hiku/introspection/graphql.py b/hiku/introspection/graphql.py index c2afe738..60477aef 100644 --- a/hiku/introspection/graphql.py +++ b/hiku/introspection/graphql.py @@ -906,7 +906,7 @@ def visit_field(self, obj: Field) -> Field: field = super(BindToSchema, self).visit_field(obj) func = self._processed.get(obj.func) if func is None: - func = self._processed[obj.func] = partial(obj.func, self.schema) + func = self._processed[obj.func] = partial(obj.func, self.schema) # type: ignore[misc] # noqa: E501 field.func = func return field @@ -993,7 +993,7 @@ def __init__( mutation_graph, ) - def __type_name__(self, node_name: t.Optional[str]) -> Field: + def __type_name__(self, node_name: str) -> Field: return Field( "__typename", String, partial(type_name_field_func, node_name) ) @@ -1003,6 +1003,7 @@ def __introspection_graph__(self) -> Graph: def visit_node(self, obj: Node) -> Node: node = super(GraphQLIntrospection, self).visit_node(obj) + assert obj.name is not None node.fields.append(self.__type_name__(obj.name)) return node @@ -1041,7 +1042,7 @@ class AsyncGraphQLIntrospection(GraphQLIntrospection): """ - def __type_name__(self, node_name: t.Optional[str]) -> Field: + def __type_name__(self, node_name: str) -> Field: return Field( "__typename", String, diff --git a/hiku/readers/graphql.py b/hiku/readers/graphql.py index 8b8120dc..7828e5ab 100644 --- a/hiku/readers/graphql.py +++ b/hiku/readers/graphql.py @@ -5,6 +5,7 @@ Support for queries encoded using GraphQL syntax. """ + from typing import Any, cast, Dict, Iterator, List, Optional, Set, Union from graphql.language import ast diff --git a/hiku/result.py b/hiku/result.py index d5b29428..efd9cce5 100644 --- a/hiku/result.py +++ b/hiku/result.py @@ -209,9 +209,11 @@ def _denormalize( ] elif graph_obj.type_enum is MaybeMany: return [ - _denormalize(graph, graph_node, v, query_obj.node) - if v is not None - else None + ( + _denormalize(graph, graph_node, v, query_obj.node) + if v is not None + else None + ) for v in result ] elif graph_obj.type_enum is Maybe and result is None: diff --git a/hiku/types.py b/hiku/types.py index 86b4004e..8fb48e3f 100644 --- a/hiku/types.py +++ b/hiku/types.py @@ -231,8 +231,7 @@ def accept(cls, visitor: "AbstractTypeVisitor") -> t.Any: return visitor.visit_typeref(cls) -class TypeRef(metaclass=TypeRefMeta): - ... +class TypeRef(metaclass=TypeRefMeta): ... class UnionRefMeta(TypingMeta): @@ -250,8 +249,7 @@ def accept(cls, visitor: "AbstractTypeVisitor") -> t.Any: return visitor.visit_unionref(cls) -class UnionRef(metaclass=UnionRefMeta): - ... +class UnionRef(metaclass=UnionRefMeta): ... class InterfaceRefMeta(TypingMeta): @@ -269,8 +267,7 @@ def accept(cls, visitor: "AbstractTypeVisitor") -> t.Any: return visitor.visit_interfaceref(cls) -class InterfaceRef(metaclass=InterfaceRefMeta): - ... +class InterfaceRef(metaclass=InterfaceRefMeta): ... class EnumRefMeta(TypingMeta): @@ -288,8 +285,7 @@ def accept(cls, visitor: "AbstractTypeVisitor") -> t.Any: return visitor.visit_enumref(cls) -class EnumRef(metaclass=EnumRefMeta): - ... +class EnumRef(metaclass=EnumRefMeta): ... RefMeta = (TypeRefMeta, UnionRefMeta, InterfaceRefMeta, EnumRefMeta) @@ -297,13 +293,11 @@ class EnumRef(metaclass=EnumRefMeta): @t.overload -def _maybe_typeref(typ: str) -> TypeRefMeta: - ... +def _maybe_typeref(typ: str) -> TypeRefMeta: ... @t.overload -def _maybe_typeref(typ: GenericMeta) -> GenericMeta: - ... +def _maybe_typeref(typ: GenericMeta) -> GenericMeta: ... def _maybe_typeref(typ: t.Union[str, GenericMeta]) -> GenericMeta: @@ -428,39 +422,32 @@ def visit_callable(self, obj: CallableMeta) -> t.Any: @t.overload -def get_type( # type: ignore[misc] - types: Types, typ: TypeRefMeta -) -> t.Type[Record]: - ... +def get_type(types: Types, typ: TypeRefMeta) -> t.Type[Record]: ... @t.overload -def get_type(types: Types, typ: UnionRefMeta) -> "Union": # type: ignore[misc] +def get_type(types: Types, typ: UnionRefMeta) -> "Union": # type: ignore[overload-overlap] # noqa: E501 ... @t.overload -def get_type( # type: ignore[misc] +def get_type( # type: ignore[overload-overlap] types: Types, typ: EnumRefMeta -) -> "BaseEnum": - ... +) -> "BaseEnum": ... @t.overload -def get_type( # type: ignore[misc] +def get_type( # type: ignore[overload-overlap] types: Types, typ: InterfaceRefMeta -) -> "Interface": - ... +) -> "Interface": ... @t.overload -def get_type(types: Types, typ: "ScalarMeta") -> "ScalarMeta": - ... +def get_type(types: Types, typ: "ScalarMeta") -> "ScalarMeta": ... @t.overload -def get_type(types: Types, typ: T) -> T: - ... +def get_type(types: Types, typ: T) -> T: ... def get_type(types: Types, typ: t.Any) -> t.Any: diff --git a/hiku/validate/graph.py b/hiku/validate/graph.py index b816201f..116b16c3 100644 --- a/hiku/validate/graph.py +++ b/hiku/validate/graph.py @@ -346,8 +346,7 @@ def visit_enum(self, obj: BaseEnum) -> t.Any: self._validate_description(obj) - def visit_scalar(self, obj: t.Type[Scalar]) -> t.Any: - ... + def visit_scalar(self, obj: t.Type[Scalar]) -> t.Any: ... def visit_root(self, obj: Root) -> None: self.visit_node(obj)