diff --git a/src/graphql/pyutils/undefined.py b/src/graphql/pyutils/undefined.py index 10e2c69e..87994300 100644 --- a/src/graphql/pyutils/undefined.py +++ b/src/graphql/pyutils/undefined.py @@ -3,6 +3,13 @@ from __future__ import annotations import warnings +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + try: + from typing import Self + except ImportError: # Python < 3.11 + from typing_extensions import Self __all__ = ["Undefined", "UndefinedType"] @@ -10,9 +17,9 @@ class UndefinedType: """Auxiliary class for creating the Undefined singleton.""" - _instance: UndefinedType | None = None + _instance: Self | None = None - def __new__(cls) -> UndefinedType: + def __new__(cls) -> Self: """Create the Undefined singleton.""" if cls._instance is None: cls._instance = super().__new__(cls) diff --git a/src/graphql/type/definition.py b/src/graphql/type/definition.py index 7ab95351..031071b1 100644 --- a/src/graphql/type/definition.py +++ b/src/graphql/type/definition.py @@ -59,6 +59,11 @@ if TYPE_CHECKING: from .schema import GraphQLSchema + try: + from typing import Self + except ImportError: # Python < 3.11 + from typing_extensions import Self + __all__ = [ "GraphQLAbstractType", @@ -232,7 +237,7 @@ class GraphQLNamedType(GraphQLType): reserved_types: Mapping[str, GraphQLNamedType] = {} - def __new__(cls, name: str, *_args: Any, **_kwargs: Any) -> GraphQLNamedType: + def __new__(cls, name: str, *_args: Any, **_kwargs: Any) -> Self: """Create a GraphQL named type.""" if name in cls.reserved_types: msg = f"Redefinition of reserved type {name!r}"