mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-04 18:07:48 +03:00 
			
		
		
		
	Rename variables called type to type_ (#1216)
Co-authored-by: Daniel Gallagher <daniellg@yelp.com>
This commit is contained in:
		
							parent
							
								
									05d96a9833
								
							
						
					
					
						commit
						bf034ca85f
					
				| 
						 | 
					@ -51,20 +51,20 @@ Example of a custom node:
 | 
				
			||||||
            name = 'Node'
 | 
					            name = 'Node'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @staticmethod
 | 
					        @staticmethod
 | 
				
			||||||
        def to_global_id(type, id):
 | 
					        def to_global_id(type_, id):
 | 
				
			||||||
            return f"{type}:{id}"
 | 
					            return f"{type_}:{id}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @staticmethod
 | 
					        @staticmethod
 | 
				
			||||||
        def get_node_from_global_id(info, global_id, only_type=None):
 | 
					        def get_node_from_global_id(info, global_id, only_type=None):
 | 
				
			||||||
            type, id = global_id.split(':')
 | 
					            type_, id = global_id.split(':')
 | 
				
			||||||
            if only_type:
 | 
					            if only_type:
 | 
				
			||||||
                # We assure that the node type that we want to retrieve
 | 
					                # We assure that the node type that we want to retrieve
 | 
				
			||||||
                # is the same that was indicated in the field type
 | 
					                # is the same that was indicated in the field type
 | 
				
			||||||
                assert type == only_type._meta.name, 'Received not compatible node.'
 | 
					                assert type_ == only_type._meta.name, 'Received not compatible node.'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if type == 'User':
 | 
					            if type_ == 'User':
 | 
				
			||||||
                return get_user(id)
 | 
					                return get_user(id)
 | 
				
			||||||
            elif type == 'Photo':
 | 
					            elif type_ == 'Photo':
 | 
				
			||||||
                return get_photo(id)
 | 
					                return get_photo(id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -845,7 +845,9 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
 | 
				
			||||||
    # Now find fields in our class.  While doing so, validate some
 | 
					    # Now find fields in our class.  While doing so, validate some
 | 
				
			||||||
    # things, and set the default values (as class attributes) where
 | 
					    # things, and set the default values (as class attributes) where
 | 
				
			||||||
    # we can.
 | 
					    # we can.
 | 
				
			||||||
    cls_fields = [_get_field(cls, name, type) for name, type in cls_annotations.items()]
 | 
					    cls_fields = [
 | 
				
			||||||
 | 
					        _get_field(cls, name, type_) for name, type_ in cls_annotations.items()
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
    for f in cls_fields:
 | 
					    for f in cls_fields:
 | 
				
			||||||
        fields[f.name] = f
 | 
					        fields[f.name] = f
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -117,19 +117,19 @@ def connection_adapter(cls, edges, pageInfo):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class IterableConnectionField(Field):
 | 
					class IterableConnectionField(Field):
 | 
				
			||||||
    def __init__(self, type, *args, **kwargs):
 | 
					    def __init__(self, type_, *args, **kwargs):
 | 
				
			||||||
        kwargs.setdefault("before", String())
 | 
					        kwargs.setdefault("before", String())
 | 
				
			||||||
        kwargs.setdefault("after", String())
 | 
					        kwargs.setdefault("after", String())
 | 
				
			||||||
        kwargs.setdefault("first", Int())
 | 
					        kwargs.setdefault("first", Int())
 | 
				
			||||||
        kwargs.setdefault("last", Int())
 | 
					        kwargs.setdefault("last", Int())
 | 
				
			||||||
        super(IterableConnectionField, self).__init__(type, *args, **kwargs)
 | 
					        super(IterableConnectionField, self).__init__(type_, *args, **kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def type(self):
 | 
					    def type(self):
 | 
				
			||||||
        type = super(IterableConnectionField, self).type
 | 
					        type_ = super(IterableConnectionField, self).type
 | 
				
			||||||
        connection_type = type
 | 
					        connection_type = type_
 | 
				
			||||||
        if isinstance(type, NonNull):
 | 
					        if isinstance(type_, NonNull):
 | 
				
			||||||
            connection_type = type.of_type
 | 
					            connection_type = type_.of_type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if is_node(connection_type):
 | 
					        if is_node(connection_type):
 | 
				
			||||||
            raise Exception(
 | 
					            raise Exception(
 | 
				
			||||||
| 
						 | 
					@ -140,7 +140,7 @@ class IterableConnectionField(Field):
 | 
				
			||||||
        assert issubclass(
 | 
					        assert issubclass(
 | 
				
			||||||
            connection_type, Connection
 | 
					            connection_type, Connection
 | 
				
			||||||
        ), f'{self.__class__.__name__} type has to be a subclass of Connection. Received "{connection_type}".'
 | 
					        ), f'{self.__class__.__name__} type has to be a subclass of Connection. Received "{connection_type}".'
 | 
				
			||||||
        return type
 | 
					        return type_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def resolve_connection(cls, connection_type, args, resolved):
 | 
					    def resolve_connection(cls, connection_type, args, resolved):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -47,15 +47,15 @@ class GlobalID(Field):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class NodeField(Field):
 | 
					class NodeField(Field):
 | 
				
			||||||
    def __init__(self, node, type=False, **kwargs):
 | 
					    def __init__(self, node, type_=False, **kwargs):
 | 
				
			||||||
        assert issubclass(node, Node), "NodeField can only operate in Nodes"
 | 
					        assert issubclass(node, Node), "NodeField can only operate in Nodes"
 | 
				
			||||||
        self.node_type = node
 | 
					        self.node_type = node
 | 
				
			||||||
        self.field_type = type
 | 
					        self.field_type = type_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        super(NodeField, self).__init__(
 | 
					        super(NodeField, self).__init__(
 | 
				
			||||||
            # If we don's specify a type, the field type will be the node
 | 
					            # If we don's specify a type, the field type will be the node
 | 
				
			||||||
            # interface
 | 
					            # interface
 | 
				
			||||||
            type or node,
 | 
					            type_ or node,
 | 
				
			||||||
            id=ID(required=True, description="The ID of the object"),
 | 
					            id=ID(required=True, description="The ID of the object"),
 | 
				
			||||||
            **kwargs,
 | 
					            **kwargs,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
| 
						 | 
					@ -125,5 +125,5 @@ class Node(AbstractNode):
 | 
				
			||||||
        return from_global_id(global_id)
 | 
					        return from_global_id(global_id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def to_global_id(cls, type, id):
 | 
					    def to_global_id(cls, type_, id):
 | 
				
			||||||
        return to_global_id(type, id)
 | 
					        return to_global_id(type_, id)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ class CustomNode(Node):
 | 
				
			||||||
        name = "Node"
 | 
					        name = "Node"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def to_global_id(type, id):
 | 
					    def to_global_id(type_, id):
 | 
				
			||||||
        return id
 | 
					        return id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,7 +40,7 @@ class Argument(MountedType):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(
 | 
					    def __init__(
 | 
				
			||||||
        self,
 | 
					        self,
 | 
				
			||||||
        type,
 | 
					        type_,
 | 
				
			||||||
        default_value=None,
 | 
					        default_value=None,
 | 
				
			||||||
        description=None,
 | 
					        description=None,
 | 
				
			||||||
        name=None,
 | 
					        name=None,
 | 
				
			||||||
| 
						 | 
					@ -50,10 +50,10 @@ class Argument(MountedType):
 | 
				
			||||||
        super(Argument, self).__init__(_creation_counter=_creation_counter)
 | 
					        super(Argument, self).__init__(_creation_counter=_creation_counter)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if required:
 | 
					        if required:
 | 
				
			||||||
            type = NonNull(type)
 | 
					            type_ = NonNull(type_)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.name = name
 | 
					        self.name = name
 | 
				
			||||||
        self._type = type
 | 
					        self._type = type_
 | 
				
			||||||
        self.default_value = default_value
 | 
					        self.default_value = default_value
 | 
				
			||||||
        self.description = description
 | 
					        self.description = description
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,10 +10,10 @@ class Dynamic(MountedType):
 | 
				
			||||||
    the schema. So we can have lazy fields.
 | 
					    the schema. So we can have lazy fields.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, type, with_schema=False, _creation_counter=None):
 | 
					    def __init__(self, type_, with_schema=False, _creation_counter=None):
 | 
				
			||||||
        super(Dynamic, self).__init__(_creation_counter=_creation_counter)
 | 
					        super(Dynamic, self).__init__(_creation_counter=_creation_counter)
 | 
				
			||||||
        assert inspect.isfunction(type) or isinstance(type, partial)
 | 
					        assert inspect.isfunction(type_) or isinstance(type_, partial)
 | 
				
			||||||
        self.type = type
 | 
					        self.type = type_
 | 
				
			||||||
        self.with_schema = with_schema
 | 
					        self.with_schema = with_schema
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_type(self, schema=None):
 | 
					    def get_type(self, schema=None):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,7 +64,7 @@ class Field(MountedType):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(
 | 
					    def __init__(
 | 
				
			||||||
        self,
 | 
					        self,
 | 
				
			||||||
        type,
 | 
					        type_,
 | 
				
			||||||
        args=None,
 | 
					        args=None,
 | 
				
			||||||
        resolver=None,
 | 
					        resolver=None,
 | 
				
			||||||
        source=None,
 | 
					        source=None,
 | 
				
			||||||
| 
						 | 
					@ -88,7 +88,7 @@ class Field(MountedType):
 | 
				
			||||||
        ), f'The default value can not be a function but received "{base_type(default_value)}".'
 | 
					        ), f'The default value can not be a function but received "{base_type(default_value)}".'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if required:
 | 
					        if required:
 | 
				
			||||||
            type = NonNull(type)
 | 
					            type_ = NonNull(type_)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Check if name is actually an argument of the field
 | 
					        # Check if name is actually an argument of the field
 | 
				
			||||||
        if isinstance(name, (Argument, UnmountedType)):
 | 
					        if isinstance(name, (Argument, UnmountedType)):
 | 
				
			||||||
| 
						 | 
					@ -101,7 +101,7 @@ class Field(MountedType):
 | 
				
			||||||
            source = None
 | 
					            source = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.name = name
 | 
					        self.name = name
 | 
				
			||||||
        self._type = type
 | 
					        self._type = type_
 | 
				
			||||||
        self.args = to_arguments(args or {}, extra_args)
 | 
					        self.args = to_arguments(args or {}, extra_args)
 | 
				
			||||||
        if source:
 | 
					        if source:
 | 
				
			||||||
            resolver = partial(source_resolver, source)
 | 
					            resolver = partial(source_resolver, source)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ class InputField(MountedType):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(
 | 
					    def __init__(
 | 
				
			||||||
        self,
 | 
					        self,
 | 
				
			||||||
        type,
 | 
					        type_,
 | 
				
			||||||
        name=None,
 | 
					        name=None,
 | 
				
			||||||
        default_value=Undefined,
 | 
					        default_value=Undefined,
 | 
				
			||||||
        deprecation_reason=None,
 | 
					        deprecation_reason=None,
 | 
				
			||||||
| 
						 | 
					@ -60,8 +60,8 @@ class InputField(MountedType):
 | 
				
			||||||
        super(InputField, self).__init__(_creation_counter=_creation_counter)
 | 
					        super(InputField, self).__init__(_creation_counter=_creation_counter)
 | 
				
			||||||
        self.name = name
 | 
					        self.name = name
 | 
				
			||||||
        if required:
 | 
					        if required:
 | 
				
			||||||
            type = NonNull(type)
 | 
					            type_ = NonNull(type_)
 | 
				
			||||||
        self._type = type
 | 
					        self._type = type_
 | 
				
			||||||
        self.deprecation_reason = deprecation_reason
 | 
					        self.deprecation_reason = deprecation_reason
 | 
				
			||||||
        self.default_value = default_value
 | 
					        self.default_value = default_value
 | 
				
			||||||
        self.description = description
 | 
					        self.description = description
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -234,10 +234,10 @@ def test_stringifies_simple_types():
 | 
				
			||||||
#         (InputObjectType, True)
 | 
					#         (InputObjectType, True)
 | 
				
			||||||
#     )
 | 
					#     )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#     for type, answer in expected:
 | 
					#     for type_, answer in expected:
 | 
				
			||||||
#         assert is_input_type(type) == answer
 | 
					#         assert is_input_type(type_) == answer
 | 
				
			||||||
#         assert is_input_type(GraphQLList(type)) == answer
 | 
					#         assert is_input_type(GraphQLList(type_)) == answer
 | 
				
			||||||
#         assert is_input_type(GraphQLNonNull(type)) == answer
 | 
					#         assert is_input_type(GraphQLNonNull(type_)) == answer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# def test_identifies_output_types():
 | 
					# def test_identifies_output_types():
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user