Skip to content

Commit 6ebce43

Browse files
authored
docs: Use lower-case generics (#17176)
Use lower-case `list`, `tuple`, `type` instead of `List`, `Tuple`, `Type` in documentation.
1 parent 82ebd86 commit 6ebce43

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

docs/source/common_issues.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ once you add annotations:
4141
4242
def foo(a: str) -> str:
4343
return '(' + a.split() + ')'
44-
# error: Unsupported operand types for + ("str" and List[str])
44+
# error: Unsupported operand types for + ("str" and "list[str]")
4545
4646
If you don't know what types to add, you can use ``Any``, but beware:
4747

@@ -226,7 +226,7 @@ dict to a new variable, as mentioned earlier:
226226

227227
.. code-block:: python
228228
229-
a: List[int] = []
229+
a: list[int] = []
230230
231231
Without the annotation mypy can't always figure out the
232232
precise type of ``a``.
@@ -238,7 +238,7 @@ modification operation in the same scope (such as ``append`` for a list):
238238

239239
.. code-block:: python
240240
241-
a = [] # Okay because followed by append, inferred type List[int]
241+
a = [] # Okay because followed by append, inferred type list[int]
242242
for i in range(n):
243243
a.append(i * i)
244244
@@ -276,7 +276,7 @@ not support ``sort()``) as a list and sort it in-place:
276276
def f(x: Sequence[int]) -> None:
277277
# Type of x is Sequence[int] here; we don't know the concrete type.
278278
x = list(x)
279-
# Type of x is List[int] here.
279+
# Type of x is list[int] here.
280280
x.sort() # Okay!
281281
282282
See :ref:`type-narrowing` for more information.
@@ -296,8 +296,8 @@ unexpected errors when combined with type inference. For example:
296296
class A: ...
297297
class B(A): ...
298298
299-
lst = [A(), A()] # Inferred type is List[A]
300-
new_lst = [B(), B()] # inferred type is List[B]
299+
lst = [A(), A()] # Inferred type is list[A]
300+
new_lst = [B(), B()] # inferred type is list[B]
301301
lst = new_lst # mypy will complain about this, because List is invariant
302302
303303
Possible strategies in such situations are:
@@ -306,7 +306,7 @@ Possible strategies in such situations are:
306306

307307
.. code-block:: python
308308
309-
new_lst: List[A] = [B(), B()]
309+
new_lst: list[A] = [B(), B()]
310310
lst = new_lst # OK
311311
312312
* Make a copy of the right hand side:
@@ -319,7 +319,7 @@ Possible strategies in such situations are:
319319

320320
.. code-block:: python
321321
322-
def f_bad(x: List[A]) -> A:
322+
def f_bad(x: list[A]) -> A:
323323
return x[0]
324324
f_bad(new_lst) # Fails
325325
@@ -489,7 +489,7 @@ understand how mypy handles a particular piece of code. Example:
489489

490490
.. code-block:: python
491491
492-
reveal_type((1, 'hello')) # Revealed type is "Tuple[builtins.int, builtins.str]"
492+
reveal_type((1, 'hello')) # Revealed type is "tuple[builtins.int, builtins.str]"
493493
494494
You can also use ``reveal_locals()`` at any line in a file
495495
to see the types of all local variables at once. Example:
@@ -622,16 +622,16 @@ instructions at the `mypyc wheels repo <https://github.com/mypyc/mypy_mypyc-whee
622622
Variables vs type aliases
623623
-------------------------
624624

625-
Mypy has both *type aliases* and variables with types like ``Type[...]``. These are
625+
Mypy has both *type aliases* and variables with types like ``type[...]``. These are
626626
subtly different, and it's important to understand how they differ to avoid pitfalls.
627627

628-
1. A variable with type ``Type[...]`` is defined using an assignment with an
628+
1. A variable with type ``type[...]`` is defined using an assignment with an
629629
explicit type annotation:
630630

631631
.. code-block:: python
632632
633633
class A: ...
634-
tp: Type[A] = A
634+
tp: type[A] = A
635635
636636
2. You can define a type alias using an assignment without an explicit type annotation
637637
at the top level of a module:
@@ -670,7 +670,7 @@ can't be defined conditionally (unless using
670670
# explicit "Type[...]" annotation
671671
Alias = B
672672
673-
tp: Type[object] # "tp" is a variable with a type object value
673+
tp: type[object] # "tp" is a variable with a type object value
674674
if random() > 0.5:
675675
tp = A
676676
else:

0 commit comments

Comments
 (0)