]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-46104: Reduce use of pre-PEP 526 syntax in typing docs (GH-30148) (GH-30180)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 18 Dec 2021 12:14:19 +0000 (04:14 -0800)
committerGitHub <noreply@github.com>
Sat, 18 Dec 2021 12:14:19 +0000 (04:14 -0800)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
(cherry picked from commit 6ada013df170b0afb6b61a0d942388c6fd81cbc9)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Doc/library/typing.rst

index 0eeaffb4352bfa2f79c06cc75a5e714ffbb11212..34aaa1fac3077b2fa36d4ef9f4a57a12c70002cd 100644 (file)
@@ -358,12 +358,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,
@@ -1445,11 +1445,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