Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
786a436
First docs work
May 13, 2023
c1f266e
More words
May 15, 2023
040c4fd
Merge remote-tracking branch 'upstream/main' into pep695docs
May 19, 2023
e3dfb27
ast changes, fix build
May 19, 2023
f5b1d86
the big PEP list
May 19, 2023
5798631
dis
May 19, 2023
0f76679
default roles
May 19, 2023
cb76021
TODOs in compound_stmts
May 19, 2023
12c1249
minor
May 19, 2023
94a4da2
Remove broken link
May 19, 2023
815a021
update dis.dis docs
May 19, 2023
17ac785
TypeAlias is deprecated
May 19, 2023
1311399
Type aliases should now use the type statement
May 19, 2023
123752c
syntax
May 19, 2023
9d6e0c0
Merge branch 'main' into pep695docs
May 19, 2023
e955a45
Expand typing.rst
May 20, 2023
d7f2b55
Finish the type statement
May 20, 2023
53c4916
What's New
May 20, 2023
edec8c3
Merge remote-tracking branch 'upstream/main' into pep695docs
May 20, 2023
bc1c1d2
typo
May 20, 2023
b1a843c
FQNs in ast.rst
May 20, 2023
e690aff
Merge remote-tracking branch 'upstream/main' into pep695docs
May 21, 2023
cc5b51c
Document TypeVar constructor signature, discuss variance
May 21, 2023
b0e1ce3
TypeVarTuple signature
May 21, 2023
382ff2c
Fix sig
May 21, 2023
db94e4f
Document TypeVar attributes, fix indentation
May 21, 2023
18b9d63
Fix TypeVarTuple indentation
May 21, 2023
b7ba811
Merge branch 'main' into pep695docs
May 22, 2023
fd1d0a8
s/typeparams/type_params/
May 22, 2023
62ba887
Apply suggestions from code review
May 22, 2023
200eba1
Reword long dis sentence
May 22, 2023
adaf874
Manual changes from Alex review
May 22, 2023
4481d6d
Merge remote-tracking branch 'upstream/main' into pep695docs
May 22, 2023
365ae7b
Improve ast.TypeAlias text
May 22, 2023
96e5d16
Document __type_params__
May 22, 2023
0204d54
Add to datamodel.rst
May 22, 2023
f426d39
Wording change
May 22, 2023
60d7783
Update Doc/library/typing.rst
May 22, 2023
63d4d84
Apply suggestions from code review
May 22, 2023
fd6751a
fix indentation
May 22, 2023
499dae1
Link to generic functions
May 22, 2023
b4172c9
Move up variance paragraph
May 22, 2023
e9bc4a8
Merge remote-tracking branch 'upstream/main' into pep695docs
May 23, 2023
0d37675
Some Alex comments
May 23, 2023
c94ee7c
Fix alignment
May 23, 2023
1630342
doctest maybe
May 23, 2023
aade45a
More Alex suggestions
May 23, 2023
57b9992
Feedback from Carl
May 23, 2023
7953d2c
Section on lazy eval
May 23, 2023
9128c72
More cross-refs
May 23, 2023
0511b6a
Can't have nice things
May 23, 2023
4fd3f02
Respond to some feedback
May 24, 2023
fff0df4
Undo unnecessary typing.rst changes
May 24, 2023
ba2a103
Merge remote-tracking branch 'upstream/main' into pep695docs
May 24, 2023
1c6807d
more words
May 24, 2023
6386475
or
May 24, 2023
cd4206c
Update Doc/reference/compound_stmts.rst
May 24, 2023
e307177
Merge branch 'main' into pep695docs
May 25, 2023
d7e1c6c
Apply suggestions from code review
May 26, 2023
f878970
More feedback from Alex
May 26, 2023
a4bd32a
fixes
May 26, 2023
ee8f952
Merge remote-tracking branch 'upstream/main' into pep695docs
May 26, 2023
7a709d7
Rewrite and extend some docstrings
May 26, 2023
0cfeb92
More comments
May 26, 2023
f978766
Docstring fixes
May 26, 2023
bba092d
tables
May 26, 2023
57ddbef
more fixes
May 26, 2023
67acd98
Merge remote-tracking branch 'upstream/main' into pep695docs
May 26, 2023
988fc7c
Merge branch 'main' into pep695docs
May 26, 2023
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
Prev Previous commit
Next Next commit
Respond to some feedback
  • Loading branch information
JelleZijlstra committed May 24, 2023
commit 4fd3f02182e4bf89c21ac65dd6c7789cd7936246
2 changes: 1 addition & 1 deletion Doc/library/typing.rst
Comment thread
JelleZijlstra marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ without the dedicated syntax, as documented below.
Here the brackets after the function name indicate a
:ref:`generic function <generic-functions>`.

For backwards compatibility reasons, generic classes can also be
For backwards compatibility, generic classes can also be
declared by explicitly inheriting from
``Generic``. In this case, the type parameters must be declared
separately::
Expand Down
31 changes: 15 additions & 16 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ non-generic counterparts.
Type parameters are declared in square brackets (``[]``) immediately
after the name of the function, class, or type alias. The type parameters
are accessible within the scope of the generic object, but not elsewhere.
Thus, after a declaration ``def func[T](): ...``, the name ``T`` is not in
Thus, after a declaration ``def func[T](): pass``, the name ``T`` is not in
the module scope. Below, the semantics of generic objects are described
with more precision. The scope of type parameters is modeled with a special
function (technically, an :ref:`annotation scope <annotation-scopes>`) that
Expand All @@ -1663,7 +1663,7 @@ attribute listing their type parameters.
Type parameters come in three kinds:

* :data:`typing.TypeVar`, introduced by a plain name (e.g., ``T``). Semantically, this
stands for a single type.
represents a single type to a type checker.
* :data:`typing.TypeVarTuple`, introduced by a name prefixed with a single
asterisk (e.g., ``*Ts``). Semantically, this stands for a tuple of any
number of types.
Expand All @@ -1672,8 +1672,7 @@ Type parameters come in three kinds:

:data:`typing.TypeVar` declarations can define *bounds* and *constraints* with
a colon (``:``) followed by an expression. A single expression after the colon
indicates a bound (e.g. ``T: int``). The expression should be a type (though this
is not enforced at runtime, only by static type checkers) and semantically, this means
indicates a bound (e.g. ``T: int``). Semantically, this means
that the :data:`!typing.TypeVar` can only represent types that are a subtype of
this bound. A parenthesized tuple of expressions after the colon indicates a
set of constraints (e.g. ``T: (str, bytes)``). Each member of the tuple should be a
Expand Down Expand Up @@ -1715,16 +1714,16 @@ Generic functions are declared as follows::

This syntax is equivalent to::

def' TYPE_PARAMS_OF_func():
annotation-def TYPE_PARAMS_OF_func():
T = typing.TypeVar("T")
def func(arg: T): ...
func.__type_params__ = (T,)
return func
func = TYPE_PARAMS_OF_func()

Here ``def'`` indicates an :ref:`annotation scope <annotation-scopes>`. (Two
other liberties are taken in the translation: no function is actually bound
to the name ``TYPE_PARAMS_OF_func``, and the syntax does not go through
Here ``annotation-def`` indicates an :ref:`annotation scope <annotation-scopes>`,
which is not actually bound to any name at runtime. (One
other liberties are taken in the translation: the syntax does not go through
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
attribute access on the :mod:`typing` module, but creates an instance of
:data:`typing.TypeVar` directly.)

Expand All @@ -1744,9 +1743,9 @@ Except for the :ref:`lazy evaluation <lazy-evaluation>` of the

DEFAULT_OF_arg = some_default

def' TYPE_PARAMS_OF_func():
annotation-def TYPE_PARAMS_OF_func():

def' BOUND_OF_T():
annotation-def BOUND_OF_T():
return int
# In reality, BOUND_OF_T() is evaluated only on demand.
T = typing.TypeVar("T", bound=BOUND_OF_T())
Expand Down Expand Up @@ -1775,15 +1774,15 @@ Generic classes are declared as follows::

This syntax is equivalent to::

def' TYPE_PARAMS_OF_Bag():
annotation-def TYPE_PARAMS_OF_Bag():
T = typing.TypeVar("T")
class Bag(typing.Generic[T]):
__type_params__ = (T,)
...
return Bag
Bag = TYPE_PARAMS_OF_Bag()

Here again ``def'`` (not a real keyword) indicates an
Here again ``annotation-def`` (not a real keyword) indicates an
:ref:`annotation scope <annotation-scopes>`, and the name
``TYPE_PARAMS_OF_Bag`` is not actually bound at runtime.

Expand All @@ -1798,7 +1797,7 @@ by this example::

This is equivalent to::

def' TYPE_PARAMS_OF_Bag():
annotation-def TYPE_PARAMS_OF_Bag():
T = typing.TypeVar("T")
class Bag(Base[T], typing.Generic[T], arg=T):
__type_params__ = (T,)
Expand All @@ -1818,16 +1817,16 @@ The :keyword:`type` statement can also be used to create a generic type alias::
Except for the :ref:`lazy evaluation <lazy-evaluation>` of the value,
this is equivalent to::

def' TYPE_PARAMS_OF_ListOrSet():
annotation-def TYPE_PARAMS_OF_ListOrSet():
T = typing.TypeVar("T")

def' VALUE_OF_ListOrSet():
annotation-def VALUE_OF_ListOrSet():
return list[T] | set[T]
# In reality, the value is lazily evaluated
return typing.TypeAliasType("ListOrSet", VALUE_OF_ListOrSet(), type_params=(T,))
ListOrSet = TYPE_PARAMS_OF_ListOrSet()

Here, ``def'`` (not a real keyword) indicates an
Here, ``annotation-def`` (not a real keyword) indicates an
:ref:`annotation scope <annotation-scopes>`. The capitalized names
like ``TYPE_PARAMS_OF_ListOrSet`` are not actually bound at runtime.

Expand Down
4 changes: 2 additions & 2 deletions Doc/reference/simple_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1033,11 +1033,11 @@ For example, the following statement creates a type alias::

This code is roughly equivalent to::

def' VALUE_OF_Point():
annotation-def VALUE_OF_Point():
return tuple[float, float]
Point = typing.TypeAliasType("Point", VALUE_OF_Point())

``def'`` indicates an :ref:`annotation scope <annotation-scopes>`, which behaves
``annotation-def`` indicates an :ref:`annotation scope <annotation-scopes>`, which behaves
mostly like a function, but with several small differences. The value of the
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
type alias is evaluated in the annotation scope. It is not evaluated when the
type alias is created, but only when the value is accessed through the type alias's
Expand Down