Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable recursive type definitions #218

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/graphql/language/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/graphql/pyutils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

from __future__ import annotations

from typing import Any, NamedTuple
from typing import NamedTuple

__all__ = ["Path"]


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)"""
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
from typing_extensions import TypeAlias


MYPY = False

__all__ = ["OverlappingFieldsCanBeMergedRule"]


Expand Down Expand Up @@ -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)
Cito marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down
2 changes: 2 additions & 0 deletions tests/execution/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading