Skip to content

Commit 2c215fc

Browse files
committed
Use some more postponed evaluation of annotations
1 parent e4c26df commit 2c215fc

File tree

11 files changed

+78
-64
lines changed

11 files changed

+78
-64
lines changed

docs/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,12 @@
120120
# We need to give autodoc a little help in this cases, too:
121121
graphql_classes = {
122122
'GraphQLAbstractType': 'type',
123+
'GraphQLFieldResolver': 'type',
123124
'GraphQLObjectType': 'type',
124125
'GraphQLOutputType': 'type',
125126
'GraphQLTypeResolver': 'type',
127+
'AwaitableOrValue': 'execution',
128+
'Middleware': 'execution',
126129
'Node': 'language',
127130
'Source': 'language',
128131
'SourceLocation': 'language'
@@ -135,13 +138,18 @@
135138
traceback
136139
types.TracebackType
137140
TypeMap
141+
AwaitableOrValue
138142
EnterLeaveVisitor
139143
FormattedSourceLocation
140144
GraphQLAbstractType
141145
GraphQLErrorExtensions
146+
GraphQLFieldResolver
147+
GraphQLTypeResolver
142148
GraphQLOutputType
149+
Middleware
143150
asyncio.events.AbstractEventLoop
144151
graphql.execution.map_async_iterator.MapAsyncIterator
152+
graphql.execution.Middleware
145153
graphql.language.lexer.EscapeSequence
146154
graphql.language.visitor.EnterLeaveVisitor
147155
graphql.type.schema.InterfaceImplementations

src/graphql/error/graphql_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def __init__(
149149
positions = [loc.start for loc in node_locations]
150150
self.positions = positions or None
151151
if positions and source:
152-
locations: Optional[List["SourceLocation"]] = [
152+
locations: Optional[List[SourceLocation]] = [
153153
source.get_location(pos) for pos in positions
154154
]
155155
else:

src/graphql/error/located_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
def located_error(
1414
original_error: Exception,
15-
nodes: Optional[Union["None", Collection["Node"]]] = None,
15+
nodes: Optional[Union[None, Collection["Node"]]] = None,
1616
path: Optional[Collection[Union[str, int]]] = None,
1717
) -> GraphQLError:
1818
"""Located GraphQL Error

src/graphql/error/syntax_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class GraphQLSyntaxError(GraphQLError):
1515
"""A GraphQLError representing a syntax error."""
1616

17-
def __init__(self, source: Source, position: int, description: str) -> None:
17+
def __init__(self, source: "Source", position: int, description: str) -> None:
1818
super().__init__(
1919
f"Syntax Error: {description}", source=source, positions=[position]
2020
)

src/graphql/execution/execute.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations # Python < 3.10
2+
13
from asyncio import ensure_future, gather
24
from collections.abc import Mapping
35
from inspect import isawaitable
@@ -238,7 +240,7 @@ def build(
238240
subscribe_field_resolver: Optional[GraphQLFieldResolver] = None,
239241
middleware: Optional[Middleware] = None,
240242
is_awaitable: Optional[Callable[[Any], bool]] = None,
241-
) -> Union[List[GraphQLError], "ExecutionContext"]:
243+
) -> Union[List[GraphQLError], ExecutionContext]:
242244
"""Build an execution context
243245
244246
Constructs a ExecutionContext object from the arguments passed to execute, which
@@ -972,7 +974,7 @@ def execute(
972974
type_resolver: Optional[GraphQLTypeResolver] = None,
973975
subscribe_field_resolver: Optional[GraphQLFieldResolver] = None,
974976
middleware: Optional[Middleware] = None,
975-
execution_context_class: Optional[Type["ExecutionContext"]] = None,
977+
execution_context_class: Optional[Type[ExecutionContext]] = None,
976978
is_awaitable: Optional[Callable[[Any], bool]] = None,
977979
) -> AwaitableOrValue[ExecutionResult]:
978980
"""Execute a GraphQL operation.
@@ -1060,7 +1062,7 @@ def execute_sync(
10601062
field_resolver: Optional[GraphQLFieldResolver] = None,
10611063
type_resolver: Optional[GraphQLTypeResolver] = None,
10621064
middleware: Optional[Middleware] = None,
1063-
execution_context_class: Optional[Type["ExecutionContext"]] = None,
1065+
execution_context_class: Optional[Type[ExecutionContext]] = None,
10641066
check_sync: bool = False,
10651067
) -> ExecutionResult:
10661068
"""Execute a GraphQL operation synchronously.

src/graphql/execution/subscribe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def subscribe(
2929
operation_name: Optional[str] = None,
3030
field_resolver: Optional[GraphQLFieldResolver] = None,
3131
subscribe_field_resolver: Optional[GraphQLFieldResolver] = None,
32-
execution_context_class: Optional[Type["ExecutionContext"]] = None,
32+
execution_context_class: Optional[Type[ExecutionContext]] = None,
3333
) -> Union[AsyncIterator[ExecutionResult], ExecutionResult]:
3434
"""Create a GraphQL subscription.
3535
@@ -97,7 +97,7 @@ async def create_source_event_stream(
9797
variable_values: Optional[Dict[str, Any]] = None,
9898
operation_name: Optional[str] = None,
9999
subscribe_field_resolver: Optional[GraphQLFieldResolver] = None,
100-
execution_context_class: Optional[Type["ExecutionContext"]] = None,
100+
execution_context_class: Optional[Type[ExecutionContext]] = None,
101101
) -> Union[AsyncIterable[Any], ExecutionResult]:
102102
"""Create source event stream
103103

src/graphql/language/ast.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class Token:
9393
value: Optional[str]
9494
# Tokens exist as nodes in a double-linked-list amongst all tokens including
9595
# ignored tokens. <SOF> is always the first node and <EOF> the last.
96-
prev: Optional["Token"]
97-
next: Optional["Token"]
96+
prev: Optional[Token]
97+
next: Optional[Token]
9898

9999
def __init__(
100100
self,
@@ -413,7 +413,7 @@ class NameNode(Node):
413413
class DocumentNode(Node):
414414
__slots__ = ("definitions",)
415415

416-
definitions: Tuple["DefinitionNode", ...]
416+
definitions: Tuple[DefinitionNode, ...]
417417

418418

419419
class DefinitionNode(Node):
@@ -424,9 +424,9 @@ class ExecutableDefinitionNode(DefinitionNode):
424424
__slots__ = "name", "directives", "variable_definitions", "selection_set"
425425

426426
name: Optional[NameNode]
427-
directives: Tuple["DirectiveNode", ...]
428-
variable_definitions: Tuple["VariableDefinitionNode", ...]
429-
selection_set: "SelectionSetNode"
427+
directives: Tuple[DirectiveNode, ...]
428+
variable_definitions: Tuple[VariableDefinitionNode, ...]
429+
selection_set: SelectionSetNode
430430

431431

432432
class OperationDefinitionNode(ExecutableDefinitionNode):
@@ -438,43 +438,43 @@ class OperationDefinitionNode(ExecutableDefinitionNode):
438438
class VariableDefinitionNode(Node):
439439
__slots__ = "variable", "type", "default_value", "directives"
440440

441-
variable: "VariableNode"
442-
type: "TypeNode"
443-
default_value: Optional["ConstValueNode"]
444-
directives: Tuple["ConstDirectiveNode", ...]
441+
variable: VariableNode
442+
type: TypeNode
443+
default_value: Optional[ConstValueNode]
444+
directives: Tuple[ConstDirectiveNode, ...]
445445

446446

447447
class SelectionSetNode(Node):
448448
__slots__ = ("selections",)
449449

450-
selections: Tuple["SelectionNode", ...]
450+
selections: Tuple[SelectionNode, ...]
451451

452452

453453
class SelectionNode(Node):
454454
__slots__ = ("directives",)
455455

456-
directives: Tuple["DirectiveNode", ...]
456+
directives: Tuple[DirectiveNode, ...]
457457

458458

459459
class FieldNode(SelectionNode):
460460
__slots__ = "alias", "name", "arguments", "selection_set"
461461

462462
alias: Optional[NameNode]
463463
name: NameNode
464-
arguments: Tuple["ArgumentNode", ...]
464+
arguments: Tuple[ArgumentNode, ...]
465465
selection_set: Optional[SelectionSetNode]
466466

467467

468468
class ArgumentNode(Node):
469469
__slots__ = "name", "value"
470470

471471
name: NameNode
472-
value: "ValueNode"
472+
value: ValueNode
473473

474474

475475
class ConstArgumentNode(ArgumentNode):
476476

477-
value: "ConstValueNode"
477+
value: ConstValueNode
478478

479479

480480
# Fragments
@@ -489,15 +489,15 @@ class FragmentSpreadNode(SelectionNode):
489489
class InlineFragmentNode(SelectionNode):
490490
__slots__ = "type_condition", "selection_set"
491491

492-
type_condition: "NamedTypeNode"
492+
type_condition: NamedTypeNode
493493
selection_set: SelectionSetNode
494494

495495

496496
class FragmentDefinitionNode(ExecutableDefinitionNode):
497497
__slots__ = ("type_condition",)
498498

499499
name: NameNode
500-
type_condition: "NamedTypeNode"
500+
type_condition: NamedTypeNode
501501

502502

503503
# Values
@@ -556,18 +556,18 @@ class ListValueNode(ValueNode):
556556

557557
class ConstListValueNode(ListValueNode):
558558

559-
values: Tuple["ConstValueNode", ...]
559+
values: Tuple[ConstValueNode, ...]
560560

561561

562562
class ObjectValueNode(ValueNode):
563563
__slots__ = ("fields",)
564564

565-
fields: Tuple["ObjectFieldNode", ...]
565+
fields: Tuple[ObjectFieldNode, ...]
566566

567567

568568
class ConstObjectValueNode(ObjectValueNode):
569569

570-
fields: Tuple["ConstObjectFieldNode", ...]
570+
fields: Tuple[ConstObjectFieldNode, ...]
571571

572572

573573
class ObjectFieldNode(Node):
@@ -579,7 +579,7 @@ class ObjectFieldNode(Node):
579579

580580
class ConstObjectFieldNode(ObjectFieldNode):
581581

582-
value: "ConstValueNode"
582+
value: ConstValueNode
583583

584584

585585
ConstValueNode = Union[
@@ -646,7 +646,7 @@ class SchemaDefinitionNode(TypeSystemDefinitionNode):
646646

647647
description: Optional[StringValueNode]
648648
directives: Tuple[ConstDirectiveNode, ...]
649-
operation_types: Tuple["OperationTypeDefinitionNode", ...]
649+
operation_types: Tuple[OperationTypeDefinitionNode, ...]
650650

651651

652652
class OperationTypeDefinitionNode(Node):
@@ -678,7 +678,7 @@ class ObjectTypeDefinitionNode(TypeDefinitionNode):
678678

679679
interfaces: Tuple[NamedTypeNode, ...]
680680
directives: Tuple[ConstDirectiveNode, ...]
681-
fields: Tuple["FieldDefinitionNode", ...]
681+
fields: Tuple[FieldDefinitionNode, ...]
682682

683683

684684
class FieldDefinitionNode(DefinitionNode):
@@ -687,7 +687,7 @@ class FieldDefinitionNode(DefinitionNode):
687687
description: Optional[StringValueNode]
688688
name: NameNode
689689
directives: Tuple[ConstDirectiveNode, ...]
690-
arguments: Tuple["InputValueDefinitionNode", ...]
690+
arguments: Tuple[InputValueDefinitionNode, ...]
691691
type: TypeNode
692692

693693

@@ -704,7 +704,7 @@ class InputValueDefinitionNode(DefinitionNode):
704704
class InterfaceTypeDefinitionNode(TypeDefinitionNode):
705705
__slots__ = "fields", "interfaces"
706706

707-
fields: Tuple["FieldDefinitionNode", ...]
707+
fields: Tuple[FieldDefinitionNode, ...]
708708
directives: Tuple[ConstDirectiveNode, ...]
709709
interfaces: Tuple[NamedTypeNode, ...]
710710

@@ -720,7 +720,7 @@ class EnumTypeDefinitionNode(TypeDefinitionNode):
720720
__slots__ = ("values",)
721721

722722
directives: Tuple[ConstDirectiveNode, ...]
723-
values: Tuple["EnumValueDefinitionNode", ...]
723+
values: Tuple[EnumValueDefinitionNode, ...]
724724

725725

726726
class EnumValueDefinitionNode(DefinitionNode):

src/graphql/language/location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __ne__(self, other: Any) -> bool:
4040
return not self == other
4141

4242

43-
def get_location(source: Source, position: int) -> SourceLocation:
43+
def get_location(source: "Source", position: int) -> SourceLocation:
4444
"""Get the line and column for a character position in the source.
4545
4646
Takes a Source and a UTF-8 character offset, and returns the corresponding line and

src/graphql/pyutils/undefined.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations # Python < 3.10
2+
13
import warnings
24
from typing import Any, Optional
35

@@ -8,9 +10,9 @@
810
class UndefinedType(ValueError):
911
"""Auxiliary class for creating the Undefined singleton."""
1012

11-
_instance: Optional["UndefinedType"] = None
13+
_instance: Optional[UndefinedType] = None
1214

13-
def __new__(cls) -> "UndefinedType":
15+
def __new__(cls) -> UndefinedType:
1416
if cls._instance is None:
1517
cls._instance = super().__new__(cls)
1618
else:

0 commit comments

Comments
 (0)