1
1
from __future__ import annotations
2
2
3
3
import functools
4
+ from collections .abc import Callable , Generator , Iterable
4
5
from typing import (
5
6
TYPE_CHECKING ,
6
7
Any ,
7
- Callable ,
8
8
Generic ,
9
- Optional ,
9
+ TypeAlias ,
10
10
TypeVar ,
11
11
cast ,
12
12
)
13
13
14
14
if TYPE_CHECKING :
15
- from collections .abc import Generator , Iterable
16
-
17
- from typing_extensions import TypeAlias
18
-
19
15
from pykka ._types import OptExcInfo
20
16
21
17
__all__ = ["Future" , "get_all" ]
26
22
M = TypeVar ("M" ) # Result of Future.map()
27
23
R = TypeVar ("R" ) # Result of Future.reduce()
28
24
29
- GetHookFunc : TypeAlias = Callable [[Optional [ float ] ], T ]
25
+ GetHookFunc : TypeAlias = Callable [[float | None ], T ]
30
26
31
27
32
28
class Future (Generic [T ]):
@@ -38,8 +34,8 @@ class Future(Generic[T]):
38
34
``await`` the future.
39
35
"""
40
36
41
- _get_hook : Optional [ GetHookFunc [T ]]
42
- _get_hook_result : Optional [ T ]
37
+ _get_hook : GetHookFunc [T ] | None
38
+ _get_hook_result : T | None
43
39
44
40
def __init__ (self ) -> None :
45
41
super ().__init__ ()
@@ -52,7 +48,7 @@ def __repr__(self) -> str:
52
48
def get (
53
49
self ,
54
50
* ,
55
- timeout : Optional [ float ] = None ,
51
+ timeout : float | None = None ,
56
52
) -> T :
57
53
"""Get the value encapsulated by the future.
58
54
@@ -82,7 +78,7 @@ def get(
82
78
83
79
def set (
84
80
self ,
85
- value : Optional [ T ] = None ,
81
+ value : T | None = None ,
86
82
) -> None :
87
83
"""Set the encapsulated value.
88
84
@@ -94,7 +90,7 @@ def set(
94
90
95
91
def set_exception (
96
92
self ,
97
- exc_info : Optional [ OptExcInfo ] = None ,
93
+ exc_info : OptExcInfo | None = None ,
98
94
) -> None :
99
95
"""Set an exception as the encapsulated value.
100
96
@@ -293,7 +289,7 @@ def __await__(self) -> Generator[None, None, T]:
293
289
def get_all (
294
290
futures : Iterable [Future [T ]],
295
291
* ,
296
- timeout : Optional [ float ] = None ,
292
+ timeout : float | None = None ,
297
293
) -> Iterable [T ]:
298
294
"""Collect all values encapsulated in the list of futures.
299
295
0 commit comments