Skip to content

Fixes for syntax errors in code examples #7651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/generics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ non-generic. For example:
KT = TypeVar('KT')
VT = TypeVar('VT')

class MyMap(Mapping[KT, VT]]): # This is a generic subclass of Mapping
class MyMap(Mapping[KT, VT]): # This is a generic subclass of Mapping
def __getitem__(self, k: KT) -> VT:
... # Implementations omitted
def __iter__(self) -> Iterator[KT]:
Expand Down Expand Up @@ -447,7 +447,7 @@ subtype of ``str``:

class S(str): pass

ss = concat(S('foo'), S('bar')))
ss = concat(S('foo'), S('bar'))

You may expect that the type of ``ss`` is ``S``, but the type is
actually ``str``: a subtype gets promoted to one of the valid values
Expand Down
12 changes: 6 additions & 6 deletions docs/source/kinds_of_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ Any)`` function signature. Example:

from typing import Callable

def arbitrary_call(f: Callable[..., int]) -> int:
return f('x') + f(y=2) # OK
def arbitrary_call(f: Callable[..., int]) -> int:
return f('x') + f(y=2) # OK

arbitrary_call(ord) # No static error, but fails at runtime
arbitrary_call(open) # Error: does not return an int
arbitrary_call(1) # Error: 'int' is not callable
arbitrary_call(ord) # No static error, but fails at runtime
arbitrary_call(open) # Error: does not return an int
arbitrary_call(1) # Error: 'int' is not callable

In situations where more precise or complex types of callbacks are
necessary one can use flexible :ref:`callback protocols <callback_protocols>`.
Expand Down Expand Up @@ -484,7 +484,7 @@ defined. Thus this code does not work as expected:
.. code-block:: python

def f(x: A) -> None: # Error: Name A not defined
....
...

class A:
...
Expand Down
2 changes: 1 addition & 1 deletion docs/source/more_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ certain values from base class instances. Example:
class UserId(int):
pass

get_by_user_id(user_id: UserId):
def get_by_user_id(user_id: UserId):
...

However, this approach introduces some runtime overhead. To avoid this, the typing
Expand Down
2 changes: 1 addition & 1 deletion docs/source/protocols.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ For example, ``IntList`` below is iterable, over ``int`` values:
from typing import Iterator, Iterable, Optional

class IntList:
def __init__(self, value: int, next: Optional[IntList]) -> None:
def __init__(self, value: int, next: Optional['IntList']) -> None:
self.value = value
self.next = next

Expand Down
2 changes: 1 addition & 1 deletion docs/source/stubgen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Stubgen can generate this stub file based on the above file:
class Window:
parent: Any = ...
width: Any = ...
height: Any: ...
height: Any = ...
def __init__(self, width, height) -> None: ...

def create_empty() -> Window: ...
Expand Down