From bbfd4342d9457c1e14ee3a4327a704b0e4a2580b Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Tue, 2 Dec 2025 12:38:17 +0900 Subject: [PATCH 1/2] Update pep-0696.rst --- peps/pep-0696.rst | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/peps/pep-0696.rst b/peps/pep-0696.rst index 79ccf5b6639..40dd03364cf 100644 --- a/peps/pep-0696.rst +++ b/peps/pep-0696.rst @@ -20,7 +20,9 @@ Abstract This PEP introduces the concept of type defaults for type parameters, including ``TypeVar``, ``ParamSpec``, and ``TypeVarTuple``, -which act as defaults for type parameters for which no type is specified. +which act as defaults for type parameters for which no type arguments +are specified explicitly with `'[]'`, or implicitly without `'[]'` +but with the type inference by an assigned value. Default type argument support is available in some popular languages such as C++, TypeScript, and Rust. A survey of type parameter syntax in @@ -34,13 +36,18 @@ Motivation :: - T = TypeVar("T", default=int) # This means that if no type is specified T = int - + T = TypeVar("T", default=int) # This means that T = int if no type argument is specified explicitly + # with `'[]'`, or implicitly without `'[]'` but with the type + # inference by an assigned value. @dataclass class Box(Generic[T]): value: T | None = None - reveal_type(Box()) # type is Box[int] + # The type argument isn't specified. + reveal_type(Box()) # type is Box[int] + + # The type argument is specified with + # the type inference by an assigned value reveal_type(Box(value="Hello World!")) # type is Box[str] One place this `regularly comes From a041e8966a6b01d63c6f65122a90255180075fbd Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Tue, 2 Dec 2025 13:04:14 +0900 Subject: [PATCH 2/2] Update pep-0696.rst --- peps/pep-0696.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/peps/pep-0696.rst b/peps/pep-0696.rst index 40dd03364cf..82361239465 100644 --- a/peps/pep-0696.rst +++ b/peps/pep-0696.rst @@ -44,12 +44,19 @@ Motivation value: T | None = None # The type argument isn't specified. - reveal_type(Box()) # type is Box[int] + reveal_type(Box()) # type is Box[int] + + # The type argument is specified with '[]'. + reveal_type(Box[str]()) # type is Box[str] # The type argument is specified with - # the type inference by an assigned value + # the type inference by an assigned value. reveal_type(Box(value="Hello World!")) # type is Box[str] + # The type argument is specified with '[]' but not with the type + # inference by an assigned value because '[]' is prioritized. + reveal_type(Box[str](value="Hello World!")) # type is Box[str] + One place this `regularly comes up `__ is ``Generator``. I propose changing the *stub definition* to something like::