From 187e3ba805e9c650dbe1bcdc249dc6b14c7509b0 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 20 Oct 2020 12:07:22 +0200 Subject: [PATCH] mypy and black fix --- graphene/relay/__init__.py | 7 +++++- graphene/relay/id_type.py | 5 +++- graphene/relay/node.py | 23 +++++++++++++++---- graphene/relay/tests/test_custom_global_id.py | 5 ++-- graphene/types/tests/test_query.py | 2 +- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/graphene/relay/__init__.py b/graphene/relay/__init__.py index a26c72c2..f1d7e6bb 100644 --- a/graphene/relay/__init__.py +++ b/graphene/relay/__init__.py @@ -1,7 +1,12 @@ from .node import Node, is_node, GlobalID from .mutation import ClientIDMutation from .connection import Connection, ConnectionField, PageInfo -from .id_type import BaseGlobalIDType, DefaultGlobalIDType, SimpleGlobalIDType, UUIDGlobalIDType +from .id_type import ( + BaseGlobalIDType, + DefaultGlobalIDType, + SimpleGlobalIDType, + UUIDGlobalIDType, +) __all__ = [ "Node", diff --git a/graphene/relay/id_type.py b/graphene/relay/id_type.py index 29aa16a4..627c3283 100644 --- a/graphene/relay/id_type.py +++ b/graphene/relay/id_type.py @@ -1,6 +1,9 @@ from graphql_relay import from_global_id, to_global_id from ..types import ID, UUID +from ..types.base import BaseType + +from typing import Type class BaseGlobalIDType: @@ -8,7 +11,7 @@ class BaseGlobalIDType: Base class that define the required attributes/method for a type. """ - graphene_type = None + graphene_type: Type[BaseType] = ID @classmethod def resolve_global_id(cls, info, global_id): diff --git a/graphene/relay/node.py b/graphene/relay/node.py index 532d6baa..3704eb87 100644 --- a/graphene/relay/node.py +++ b/graphene/relay/node.py @@ -26,8 +26,18 @@ def is_node(objecttype): class GlobalID(Field): - def __init__(self, node=None, parent_type=None, required=True, global_id_type=DefaultGlobalIDType, *args, **kwargs): - super(GlobalID, self).__init__(global_id_type.graphene_type, required=required, *args, **kwargs) + def __init__( + self, + node=None, + parent_type=None, + required=True, + global_id_type=DefaultGlobalIDType, + *args, + **kwargs + ): + super(GlobalID, self).__init__( + global_id_type.graphene_type, required=required, *args, **kwargs + ) self.node = node or Node self.parent_type_name = parent_type._meta.name if parent_type else None @@ -70,12 +80,15 @@ class AbstractNode(Interface): @classmethod def __init_subclass_with_meta__(cls, global_id_type=DefaultGlobalIDType, **options): - assert issubclass(global_id_type, BaseGlobalIDType), \ - "Custom ID type need to be implemented as a subclass of BaseGlobalIDType." + assert issubclass( + global_id_type, BaseGlobalIDType + ), "Custom ID type need to be implemented as a subclass of BaseGlobalIDType." _meta = InterfaceOptions(cls) _meta.global_id_type = global_id_type _meta.fields = OrderedDict( - id=GlobalID(cls, global_id_type=global_id_type, description="The ID of the object.") + id=GlobalID( + cls, global_id_type=global_id_type, description="The ID of the object." + ) ) super(AbstractNode, cls).__init_subclass_with_meta__(_meta=_meta, **options) diff --git a/graphene/relay/tests/test_custom_global_id.py b/graphene/relay/tests/test_custom_global_id.py index 1e58022f..ae43db9c 100644 --- a/graphene/relay/tests/test_custom_global_id.py +++ b/graphene/relay/tests/test_custom_global_id.py @@ -3,7 +3,6 @@ from uuid import uuid4 from graphql import graphql -from ..connection import Connection, ConnectionField from ..id_type import BaseGlobalIDType, SimpleGlobalIDType, UUIDGlobalIDType from ..node import Node from ...types import Int, ObjectType, Schema, String @@ -60,7 +59,9 @@ class TestUUIDGlobalID: } }""" # UUID need to be converted to string for serialization - result = graphql(self.schema, query, variable_values={"id": str(self.user_list[0]["id"])}) + result = graphql( + self.schema, query, variable_values={"id": str(self.user_list[0]["id"])} + ) assert not result.errors assert result.data["user"]["id"] == str(self.user_list[0]["id"]) assert result.data["user"]["name"] == self.user_list[0]["name"] diff --git a/graphene/types/tests/test_query.py b/graphene/types/tests/test_query.py index 8681e462..0885e22b 100644 --- a/graphene/types/tests/test_query.py +++ b/graphene/types/tests/test_query.py @@ -399,7 +399,7 @@ def test_big_list_of_containers_multiple_fields_query_benchmark(benchmark): def test_big_list_of_containers_multiple_fields_custom_resolvers_query_benchmark( - benchmark + benchmark, ): class Container(ObjectType): x = Int()