]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46104: Reduce use of pre-PEP 526 syntax in typing docs (GH-30148)
authorAlex Waygood <Alex.Waygood@Gmail.com>
Sat, 18 Dec 2021 10:23:51 +0000 (10:23 +0000)
committerGitHub <noreply@github.com>
Sat, 18 Dec 2021 10:23:51 +0000 (18:23 +0800)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Doc/library/typing.rst

index 735d477db4371ed9740ba1aa29abe572ae940c55..ec1b8d1a5ebcc99dadc0576f801968c4ee2f9122 100644 (file)
@@ -428,12 +428,12 @@ value of type :data:`Any` and assign it to any variable::
 
    from typing import Any
 
-   a = None    # type: Any
-   a = []      # OK
-   a = 2       # OK
+   a: Any = None
+   a = []          # OK
+   a = 2           # OK
 
-   s = ''      # type: str
-   s = a       # OK
+   s = ''          # Inferred type of 's' is str
+   s = a           # OK
 
    def foo(item: Any) -> int:
        # Typechecks; 'item' could be any type,
@@ -1779,11 +1779,10 @@ Asynchronous programming
    correspond to those of :class:`Generator`, for example::
 
       from collections.abc import Coroutine
-      c = None # type: Coroutine[list[str], str, int]
-      ...
-      x = c.send('hi') # type: list[str]
+      c: Coroutine[list[str], str, int]  # Some coroutine defined elsewhere
+      x = c.send('hi')                   # Inferred type of 'x' is list[str]
       async def bar() -> None:
-          x = await c # type: int
+          y = await c                    # Inferred type of 'y' is int
 
    .. versionadded:: 3.5.3