Skip to content

Commit 2988ed5

Browse files
author
Awais Hussain
committed
Remove type annotations from TypeAdapter for py2.7 compatibility
Previously we were using Python3.5+ type annotation syntax but this is not backwards compatible so we are removing it.
1 parent 0fd8937 commit 2988ed5

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

gql/type_adapter.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from typing import Any, Dict, Callable, Optional, List
2-
3-
from graphql.type.schema import GraphQLSchema
4-
from graphql.type.definition import GraphQLObjectType, GraphQLField, GraphQLScalarType
1+
from graphql.type.definition import GraphQLObjectType, GraphQLScalarType
52

63

74
class TypeAdapter(object):
@@ -23,15 +20,15 @@ class TypeAdapter(object):
2320
apply(): pass in a GQL response to replace all instances of custom
2421
scalar strings with their deserialized representation."""
2522

26-
def __init__(self, schema: GraphQLSchema, custom_types: Dict[str, Any] = {}) -> None:
23+
def __init__(self, schema, custom_types = {}):
2724
""" schema: a graphQL schema in the GraphQLSchema format
2825
custom_types: a Dict[str, Any],
2926
where str is the name of the custom scalar type, and
3027
Any is a class which has a `parse_value(str)` function"""
3128
self.schema = schema
3229
self.custom_types = custom_types
3330

34-
def _follow_type_chain(self, node: Any) -> Any:
31+
def _follow_type_chain(self, node):
3532
""" Get the type of the schema node in question.
3633
3734
In the GraphQL schema, GraphQLFields have a "type" property. However, often
@@ -47,15 +44,15 @@ def _follow_type_chain(self, node: Any) -> Any:
4744

4845
return field_type
4946

50-
def _get_scalar_type_name(self, field: GraphQLField) -> Optional[str]:
47+
def _get_scalar_type_name(self, field):
5148
"""Returns the name of the type if the type is a scalar type.
5249
Returns None otherwise"""
5350
node = self._follow_type_chain(field)
5451
if isinstance(node, GraphQLScalarType):
5552
return node.name
5653
return None
5754

58-
def _lookup_scalar_type(self, keys: List[str]) -> Optional[str]:
55+
def _lookup_scalar_type(self, keys):
5956
"""Search through the GQL schema and return the type identified by 'keys'.
6057
6158
If keys (e.g. ['film', 'release_date']) points to a scalar type, then
@@ -68,7 +65,7 @@ def _lookup_scalar_type(self, keys: List[str]) -> Optional[str]:
6865
By default the root level is `schema.query`, if that fails, then we check
6966
`schema.mutation`."""
7067

71-
def traverse_schema(node: Any, lookup: List[str]):
68+
def traverse_schema(node, lookup):
7269
if not lookup:
7370
return self._get_scalar_type_name(node)
7471

@@ -87,7 +84,7 @@ def traverse_schema(node: Any, lookup: List[str]):
8784
except (KeyError, AttributeError):
8885
return None
8986

90-
def _get_decoded_scalar_type(self, keys: List[str], value: Any) -> Any:
87+
def _get_decoded_scalar_type(self, keys, value):
9188
"""Get the decoded value of the type identified by `keys`.
9289
9390
If the type is not a custom scalar, then return the original value.
@@ -99,7 +96,7 @@ def _get_decoded_scalar_type(self, keys: List[str], value: Any) -> Any:
9996
return self.custom_types[scalar_type].parse_value(value)
10097
return value
10198

102-
def convert_scalars(self, response: Dict[str, Any]) -> Dict[str, Any]:
99+
def convert_scalars(self, response):
103100
"""Recursively traverse the GQL response
104101
105102
Recursively traverses the GQL response and calls _get_decoded_scalar_type()
@@ -110,7 +107,7 @@ def convert_scalars(self, response: Dict[str, Any]) -> Dict[str, Any]:
110107
111108
Builds a new tree with the substituted values so old `response` is not
112109
modified."""
113-
def iterate(node: Any, keys: List[str] = []):
110+
def iterate(node, keys = []):
114111
if isinstance(node, dict):
115112
return {_key: iterate(value, keys + [_key]) for _key, value in node.items()}
116113
elif isinstance(node, list):

0 commit comments

Comments
 (0)