Skip to content

Commit 23e2d0f

Browse files
authored
[mypyc] Use lower-case generic types such as "list[t]" in docs (#18576)
We no longer support 3.8, so all supported Python versions support `list[t]` and friends.
1 parent ce1be2a commit 23e2d0f

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

mypyc/doc/differences_from_python.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ performance.
107107
integer values. A side effect of this is that the exact runtime type of
108108
``int`` values is lost. For example, consider this simple function::
109109

110-
def first_int(x: List[int]) -> int:
110+
def first_int(x: list[int]) -> int:
111111
return x[0]
112112

113113
print(first_int([True])) # Output is 1, instead of True!

mypyc/doc/native_classes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ These non-native classes can be used as base classes of native
5656
classes:
5757

5858
* ``object``
59-
* ``dict`` (and ``Dict[k, v]``)
59+
* ``dict`` (and ``dict[k, v]``)
6060
* ``BaseException``
6161
* ``Exception``
6262
* ``ValueError``

mypyc/doc/performance_tips_and_tricks.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ here we call ``acme.get_items()``, but it has no type annotation. We
5757
can use an explicit type annotation for the variable to which we
5858
assign the result::
5959

60-
from typing import List, Tuple
6160
import acme
6261

6362
def work() -> None:
6463
# Annotate "items" to help mypyc
65-
items: List[Tuple[int, str]] = acme.get_items()
64+
items: list[tuple[int, str]] = acme.get_items()
6665
for item in items:
6766
... # Do some work here
6867

@@ -140,7 +139,7 @@ Similarly, caching a frequently called method in a local variable can
140139
help in CPython, but it can slow things down in compiled code, since
141140
the code won't use :ref:`early binding <early-binding>`::
142141

143-
def squares(n: int) -> List[int]:
142+
def squares(n: int) -> list[int]:
144143
a = []
145144
append = a.append # Not a good idea in compiled code!
146145
for i in range(n):

mypyc/doc/using_type_annotations.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ implementations:
3737
* ``float`` (:ref:`native operations <float-ops>`)
3838
* ``bool`` (:ref:`native operations <bool-ops>`)
3939
* ``str`` (:ref:`native operations <str-ops>`)
40-
* ``List[T]`` (:ref:`native operations <list-ops>`)
41-
* ``Dict[K, V]`` (:ref:`native operations <dict-ops>`)
42-
* ``Set[T]`` (:ref:`native operations <set-ops>`)
43-
* ``Tuple[T, ...]`` (variable-length tuple; :ref:`native operations <tuple-ops>`)
40+
* ``list[T]`` (:ref:`native operations <list-ops>`)
41+
* ``dict[K, V]`` (:ref:`native operations <dict-ops>`)
42+
* ``set[T]`` (:ref:`native operations <set-ops>`)
43+
* ``tuple[T, ...]`` (variable-length tuple; :ref:`native operations <tuple-ops>`)
4444
* ``None``
4545

4646
The link after each type lists all supported native, optimized
@@ -61,10 +61,10 @@ variable. For example, here we have a runtime type error on the final
6161
line of ``example`` (the ``Any`` type means an arbitrary, unchecked
6262
value)::
6363

64-
from typing import List, Any
64+
from typing import Any
6565

66-
def example(a: List[Any]) -> None:
67-
b: List[int] = a # No error -- items are not checked
66+
def example(a: list[Any]) -> None:
67+
b: list[int] = a # No error -- items are not checked
6868
print(b[0]) # Error here -- got str, but expected int
6969

7070
example(["x"])
@@ -126,7 +126,7 @@ Tuple types
126126

127127
Fixed-length
128128
`tuple types <https://mypy.readthedocs.io/en/stable/kinds_of_types.html#tuple-types>`_
129-
such as ``Tuple[int, str]`` are represented
129+
such as ``tuple[int, str]`` are represented
130130
as :ref:`value types <value-and-heap-types>` when stored in variables,
131131
passed as arguments, or returned from functions. Value types are
132132
allocated in the low-level machine stack or in CPU registers, as

0 commit comments

Comments
 (0)