@@ -34,29 +34,24 @@ Type aliases may be as complex as type hints in annotations --
3434anything that is acceptable as a type hint is acceptable in a type
3535alias::
3636
37- from typing import TypeVar
3837 from collections.abc import Iterable
3938
40- T = TypeVar('T', bound=float)
41- Vector = Iterable[tuple[T, T]]
39+ type Vector[T: float] = Iterable[tuple[T, T]]
4240
43- def inproduct(v: Vector[T]) -> T:
41+ def inproduct[T: float] (v: Vector[T]) -> T:
4442 return sum(x*y for x, y in v)
45- def dilate(v: Vector[T], scale: T) -> Vector[T]:
43+ def dilate[T: float] (v: Vector[T], scale: T) -> Vector[T]:
4644 return ((x * scale, y * scale) for x, y in v)
4745 vec: Vector[float] = []
4846
4947
5048This is equivalent to::
5149
52- from typing import TypeVar
5350 from collections.abc import Iterable
5451
55- T = TypeVar('T', bound=float)
56-
57- def inproduct(v: Iterable[tuple[T, T]]) -> T:
52+ def inproduct[T: float](v: Iterable[tuple[T, T]]) -> T:
5853 return sum(x*y for x, y in v)
59- def dilate(v: Iterable[tuple[T, T]], scale: T) -> Iterable[tuple[T, T]]:
54+ def dilate[T: float] (v: Iterable[tuple[T, T]], scale: T) -> Iterable[tuple[T, T]]:
6055 return ((x * scale, y * scale) for x, y in v)
6156 vec: Iterable[tuple[float, float]] = []
6257
0 commit comments