Skip to content

Commit b43c820

Browse files
committed
Remove runtime checks that duplicate type hints
The code contained many runtime checks that threw TypeErrors if wrong types were passed, even though it is considered to be more "pythonic" to not check types at runtime at all. In general, these checks add runtime cost and we can't realistically check all arguments to all functions. Instead we should focus on adding more asserts on stuff that can't be checked using type hints. If runtime checks are desired, they can still be added by using runtime type-checkers like Beartype. Replicates graphql/graphql-js@a4b085b
1 parent 0dc7b09 commit b43c820

22 files changed

+165
-1710
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ a query language for APIs created by Facebook.
1010
![Lint Status](https://github.com/graphql-python/graphql-core/actions/workflows/lint.yml/badge.svg)
1111
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
1212

13-
An extensive test suite with over 2400 unit tests and 100% coverage comprises a
13+
An extensive test suite with over 2300 unit tests and 100% coverage comprises a
1414
replication of the complete test suite of GraphQL.js, making sure this port is
1515
reliable and compatible with GraphQL.js.
1616

src/graphql/execution/execute.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def build(
251251
For internal use only.
252252
"""
253253
# If arguments are missing or incorrect, throw an error.
254-
assert_valid_execution_arguments(schema, document, raw_variable_values)
254+
assert_valid_execution_arguments(schema)
255255

256256
operation: Optional[OperationDefinitionNode] = None
257257
fragments: Dict[str, FragmentDefinitionNode] = {}
@@ -1104,8 +1104,6 @@ def execute_sync(
11041104

11051105
def assert_valid_execution_arguments(
11061106
schema: GraphQLSchema,
1107-
document: DocumentNode,
1108-
raw_variable_values: Optional[Dict[str, Any]] = None,
11091107
) -> None:
11101108
"""Check that the arguments are acceptable.
11111109
@@ -1114,20 +1112,9 @@ def assert_valid_execution_arguments(
11141112
11151113
For internal use only.
11161114
"""
1117-
if not document:
1118-
raise TypeError("Must provide document.")
1119-
11201115
# If the schema used for execution is invalid, throw an error.
11211116
assert_valid_schema(schema)
11221117

1123-
# Variables, if provided, must be a dictionary.
1124-
if not (raw_variable_values is None or isinstance(raw_variable_values, dict)):
1125-
raise TypeError(
1126-
"Variable values must be provided as a dictionary"
1127-
" with variable names as keys. Perhaps look to see"
1128-
" if an unparsed JSON string was provided."
1129-
)
1130-
11311118

11321119
def invalid_return_type_error(
11331120
return_type: GraphQLObjectType, result: Any, field_nodes: List[FieldNode]
@@ -1345,7 +1332,7 @@ def create_source_event_stream(
13451332
"""
13461333
# If arguments are missing or incorrectly typed, this is an internal developer
13471334
# mistake which should throw an early error.
1348-
assert_valid_execution_arguments(schema, document, variable_values)
1335+
assert_valid_execution_arguments(schema)
13491336

13501337
if not execution_context_class:
13511338
execution_context_class = ExecutionContext

0 commit comments

Comments
 (0)