Update the type alias example in PEP 484 (#118)

This commit is contained in:
Ivan Levkivskyi 2016-10-18 17:07:44 +02:00 committed by Guido van Rossum
parent 1cdddf8b00
commit 68ef9a665b
1 changed files with 8 additions and 1 deletions

View File

@ -217,8 +217,12 @@ alias::
T = TypeVar('T', int, float, complex)
Vector = Iterable[Tuple[T, T]]
def inproduct(v: Vector) -> T:
def inproduct(v: Vector[T]) -> T:
return sum(x*y for x, y in v)
def dilate(v: Vector[T], scale: T) -> Vector[T]:
return ((x * scale, y * scale) for x, y in v)
vec = [] # type: Vector[float]
This is equivalent to::
@ -228,6 +232,9 @@ This is equivalent to::
def inproduct(v: Iterable[Tuple[T, T]]) -> T:
return sum(x*y for x, y in v)
def dilate(v: Iterable[Tuple[T, T]], scale: T) -> Iterable[Tuple[T, T]]:
return ((x * scale, y * scale) for x, y in v)
vec = [] # type: Iterable[Tuple[float, float]]
Callable