Skip to content

Commit beec11a

Browse files
hoeflingGuido van Rossum
authored andcommitted
Fixes for syntax errors in code examples (python#7651)
Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>
1 parent 11df39f commit beec11a

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

docs/source/generics.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ non-generic. For example:
122122
KT = TypeVar('KT')
123123
VT = TypeVar('VT')
124124
125-
class MyMap(Mapping[KT, VT]]): # This is a generic subclass of Mapping
125+
class MyMap(Mapping[KT, VT]): # This is a generic subclass of Mapping
126126
def __getitem__(self, k: KT) -> VT:
127127
... # Implementations omitted
128128
def __iter__(self) -> Iterator[KT]:
@@ -447,7 +447,7 @@ subtype of ``str``:
447447
448448
class S(str): pass
449449
450-
ss = concat(S('foo'), S('bar')))
450+
ss = concat(S('foo'), S('bar'))
451451
452452
You may expect that the type of ``ss`` is ``S``, but the type is
453453
actually ``str``: a subtype gets promoted to one of the valid values

docs/source/kinds_of_types.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ Any)`` function signature. Example:
179179
180180
from typing import Callable
181181
182-
def arbitrary_call(f: Callable[..., int]) -> int:
183-
return f('x') + f(y=2) # OK
182+
def arbitrary_call(f: Callable[..., int]) -> int:
183+
return f('x') + f(y=2) # OK
184184
185-
arbitrary_call(ord) # No static error, but fails at runtime
186-
arbitrary_call(open) # Error: does not return an int
187-
arbitrary_call(1) # Error: 'int' is not callable
185+
arbitrary_call(ord) # No static error, but fails at runtime
186+
arbitrary_call(open) # Error: does not return an int
187+
arbitrary_call(1) # Error: 'int' is not callable
188188
189189
In situations where more precise or complex types of callbacks are
190190
necessary one can use flexible :ref:`callback protocols <callback_protocols>`.
@@ -484,7 +484,7 @@ defined. Thus this code does not work as expected:
484484
.. code-block:: python
485485
486486
def f(x: A) -> None: # Error: Name A not defined
487-
....
487+
...
488488
489489
class A:
490490
...

docs/source/more_types.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ certain values from base class instances. Example:
8080
class UserId(int):
8181
pass
8282
83-
get_by_user_id(user_id: UserId):
83+
def get_by_user_id(user_id: UserId):
8484
...
8585
8686
However, this approach introduces some runtime overhead. To avoid this, the typing

docs/source/protocols.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ For example, ``IntList`` below is iterable, over ``int`` values:
3737
from typing import Iterator, Iterable, Optional
3838
3939
class IntList:
40-
def __init__(self, value: int, next: Optional[IntList]) -> None:
40+
def __init__(self, value: int, next: Optional['IntList']) -> None:
4141
self.value = value
4242
self.next = next
4343

docs/source/stubgen.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Stubgen can generate this stub file based on the above file:
4040
class Window:
4141
parent: Any = ...
4242
width: Any = ...
43-
height: Any: ...
43+
height: Any = ...
4444
def __init__(self, width, height) -> None: ...
4545
4646
def create_empty() -> Window: ...

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy