Skip to content

Commit bbfd434

Browse files
authored
Update pep-0696.rst
1 parent da0dc71 commit bbfd434

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

peps/pep-0696.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ Abstract
2020

2121
This PEP introduces the concept of type defaults for type parameters,
2222
including ``TypeVar``, ``ParamSpec``, and ``TypeVarTuple``,
23-
which act as defaults for type parameters for which no type is specified.
23+
which act as defaults for type parameters for which no type arguments
24+
are specified explicitly with `'[]'`, or implicitly without `'[]'`
25+
but with the type inference by an assigned value.
2426

2527
Default type argument support is available in some popular languages
2628
such as C++, TypeScript, and Rust. A survey of type parameter syntax in
@@ -34,13 +36,18 @@ Motivation
3436

3537
::
3638

37-
T = TypeVar("T", default=int) # This means that if no type is specified T = int
38-
39+
T = TypeVar("T", default=int) # This means that T = int if no type argument is specified explicitly
40+
# with `'[]'`, or implicitly without `'[]'` but with the type
41+
# inference by an assigned value.
3942
@dataclass
4043
class Box(Generic[T]):
4144
value: T | None = None
4245

43-
reveal_type(Box()) # type is Box[int]
46+
# The type argument isn't specified.
47+
reveal_type(Box()) # type is Box[int]
48+
49+
# The type argument is specified with
50+
# the type inference by an assigned value
4451
reveal_type(Box(value="Hello World!")) # type is Box[str]
4552

4653
One place this `regularly comes

0 commit comments

Comments
 (0)