From 1b9aff4d317f30fadeb5816effd0d0bb618a71d1 Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Sat, 28 Feb 2026 11:51:09 -0800 Subject: [PATCH 1/2] Switch to typing_extensions.Self for __new__ implementations --- src/graphql/pyutils/undefined.py | 3 ++- src/graphql/type/definition.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/graphql/pyutils/undefined.py b/src/graphql/pyutils/undefined.py index 10e2c69e..9e2735ca 100644 --- a/src/graphql/pyutils/undefined.py +++ b/src/graphql/pyutils/undefined.py @@ -1,6 +1,7 @@ """The Undefined value""" from __future__ import annotations +from typing_extensions import Self import warnings @@ -12,7 +13,7 @@ class UndefinedType: _instance: UndefinedType | 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..596a5601 100644 --- a/src/graphql/type/definition.py +++ b/src/graphql/type/definition.py @@ -14,6 +14,7 @@ cast, overload, ) +from typing_extensions import Self if TYPE_CHECKING: from typing import TypeAlias, TypeGuard @@ -232,7 +233,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}" From 69bb0110034c3d2ae70882f7bb48adf1a0842155 Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Sun, 1 Mar 2026 09:59:08 -0800 Subject: [PATCH 2/2] Apply requests from review + failing CI --- src/graphql/pyutils/undefined.py | 10 ++++++++-- src/graphql/type/definition.py | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/graphql/pyutils/undefined.py b/src/graphql/pyutils/undefined.py index 9e2735ca..87994300 100644 --- a/src/graphql/pyutils/undefined.py +++ b/src/graphql/pyutils/undefined.py @@ -1,9 +1,15 @@ """The Undefined value""" from __future__ import annotations -from typing_extensions import Self 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"] @@ -11,7 +17,7 @@ class UndefinedType: """Auxiliary class for creating the Undefined singleton.""" - _instance: UndefinedType | None = None + _instance: Self | None = None def __new__(cls) -> Self: """Create the Undefined singleton.""" diff --git a/src/graphql/type/definition.py b/src/graphql/type/definition.py index 596a5601..031071b1 100644 --- a/src/graphql/type/definition.py +++ b/src/graphql/type/definition.py @@ -14,7 +14,6 @@ cast, overload, ) -from typing_extensions import Self if TYPE_CHECKING: from typing import TypeAlias, TypeGuard @@ -60,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",