Skip to content

Commit

Permalink
Improved ExecutionResult typing
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Jul 19, 2018
1 parent 0cef6fb commit 934deca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 1 addition & 3 deletions graphql/error/format_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

# Necessary for static type checking
if False: # flake8: noqa
from .base import GraphQLError
from .located_error import GraphQLLocatedError
from typing import Any, Dict, Union


def format_error(error):
# type: (Union[GraphQLError, GraphQLLocatedError]) -> Dict[str, Any]
# type: (Exception) -> Dict[str, Any]
formatted_error = {"message": text_type(error)} # type: Dict[str, Any]
if isinstance(error, GraphQLError):
if error.locations is not None:
Expand Down
9 changes: 6 additions & 3 deletions graphql/execution/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
default_resolve_fn,
get_field_def,
)
from ..pyutils.ordereddict import OrderedDict
from ..error.format_error import format_error as default_format_error

# Necessary for static type checking
if False: # flake8: noqa
from typing import Any, Optional, Dict, List, Union
from typing import Any, Optional, Dict, List, Union, Callable, Type
from ..language.ast import Field, OperationDefinition
from ..type.definition import GraphQLList, GraphQLObjectType, GraphQLScalarType
from ..type.schema import GraphQLSchema
Expand All @@ -28,7 +29,7 @@ class ExecutionResult(object):
__slots__ = "data", "errors", "invalid", "extensions"

def __init__(self, data=None, errors=None, invalid=False, extensions=None):
# type: (Any, Any, bool, Optional[Any]) -> None
# type: (Optional[Dict], Optional[List[Exception]], bool, Optional[Any]) -> None
self.data = data
self.errors = errors
self.extensions = extensions or dict()
Expand All @@ -39,14 +40,16 @@ def __init__(self, data=None, errors=None, invalid=False, extensions=None):
self.invalid = invalid

def __eq__(self, other):
# type: (Any) -> bool
return self is other or (
isinstance(other, ExecutionResult)
and self.data == other.data
and self.errors == other.errors
and self.invalid == other.invalid
)

def to_dict(self, format_error=None, dict_class=dict):
def to_dict(self, format_error=None, dict_class=OrderedDict):
# type: (Optional[Callable[[Exception], Dict]], Type[Dict]) -> Dict[str, Any]
if format_error is None:
format_error = default_format_error

Expand Down

0 comments on commit 934deca

Please sign in to comment.