diff --git a/src/graphql/language/visitor.py b/src/graphql/language/visitor.py index 0538c2e2..be410466 100644 --- a/src/graphql/language/visitor.py +++ b/src/graphql/language/visitor.py @@ -162,7 +162,7 @@ class Stack(NamedTuple): idx: int keys: tuple[Node, ...] edits: list[tuple[int | str, Node]] - prev: Any # 'Stack' (python/mypy/issues/731) + prev: Stack def visit( diff --git a/src/graphql/pyutils/path.py b/src/graphql/pyutils/path.py index 089f5970..cc2202c4 100644 --- a/src/graphql/pyutils/path.py +++ b/src/graphql/pyutils/path.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import Any, NamedTuple +from typing import NamedTuple __all__ = ["Path"] @@ -10,7 +10,7 @@ class Path(NamedTuple): """A generic path of string or integer indices""" - prev: Any # Optional['Path'] (python/mypy/issues/731) + prev: Path | None """path with the previous indices""" key: str | int """current index in the path (string or integer)""" @@ -25,7 +25,7 @@ def as_list(self) -> list[str | int]: """Return a list of the path keys.""" flattened: list[str | int] = [] append = flattened.append - curr: Path = self + curr: Path | None = self while curr: append(curr.key) curr = curr.prev diff --git a/src/graphql/validation/rules/overlapping_fields_can_be_merged.py b/src/graphql/validation/rules/overlapping_fields_can_be_merged.py index b79bf2a6..b077958b 100644 --- a/src/graphql/validation/rules/overlapping_fields_can_be_merged.py +++ b/src/graphql/validation/rules/overlapping_fields_can_be_merged.py @@ -38,8 +38,6 @@ from typing_extensions import TypeAlias -MYPY = False - __all__ = ["OverlappingFieldsCanBeMergedRule"] @@ -98,10 +96,7 @@ def enter_selection_set(self, selection_set: SelectionSetNode, *_args: Any) -> N # Field name and reason. ConflictReason: TypeAlias = Tuple[str, "ConflictReasonMessage"] # Reason is a string, or a nested list of conflicts. -if MYPY: # recursive types not fully supported yet (/python/mypy/issues/731) - ConflictReasonMessage: TypeAlias = Union[str, List] -else: - ConflictReasonMessage: TypeAlias = Union[str, List[ConflictReason]] +ConflictReasonMessage: TypeAlias = Union[str, List[ConflictReason]] # Tuple defining a field node in a context. NodeAndDef: TypeAlias = Tuple[GraphQLCompositeType, FieldNode, Optional[GraphQLField]] # Dictionary of lists of those. diff --git a/tests/execution/test_executor.py b/tests/execution/test_executor.py index b75aaad5..391a1de6 100644 --- a/tests/execution/test_executor.py +++ b/tests/execution/test_executor.py @@ -308,9 +308,11 @@ def resolve_type(_val, _info, _type): prev, key, typename = path assert key == "l2" assert typename == "SomeObject" + assert prev is not None prev, key, typename = prev assert key == 0 assert typename is None + assert prev is not None prev, key, typename = prev assert key == "l1" assert typename == "SomeQuery"