Skip to content

Commit 9622bbf

Browse files
committed
add comprehensive static typing of return types of user-facing functions; resolve remaining type checker errors
1 parent ca5c06f commit 9622bbf

File tree

2 files changed

+176
-230
lines changed

2 files changed

+176
-230
lines changed

picamera2/job.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from collections.abc import Callable
12
from concurrent.futures import CancelledError, Future
2-
from typing import Callable, Generic, List, Optional, Tuple, TypeVar, cast
3+
from typing import Any, Generic, Literal, Optional, TypeVar, Union
34

4-
T = TypeVar('T')
5+
T = TypeVar("T")
56

67

78
class Job(Generic[T]):
@@ -23,17 +24,12 @@ class Job(Generic[T]):
2324
Picamera2.switch_mode_and_capture_array.
2425
"""
2526

26-
_functions: List[Callable[[], Tuple[bool, T]]]
27-
_future: Future[T]
28-
_signal_function: Optional[Callable[['Job[T]'], None]]
29-
_result: Optional[T]
30-
calls: int
31-
32-
def __init__(
33-
self,
34-
functions: List[Callable[[], Tuple[bool, T]]],
35-
signal_function: Optional[Callable[['Job[T]'], None]] = None,
36-
) -> None:
27+
def __init__(self, functions: list[Callable[..., Union[
28+
tuple[Literal[False], None],
29+
tuple[Literal[True], Any],
30+
tuple[Literal[True], T]
31+
]]], signal_function=None
32+
):
3733
self._functions = functions
3834
self._future = Future()
3935
self._future.set_running_or_notify_cancel()
@@ -80,7 +76,7 @@ def signal(self) -> None:
8076
assert not self._functions, "Job not finished!"
8177

8278
if not self._future.done():
83-
self._future.set_result(cast(T, self._result))
79+
self._future.set_result(self._result)
8480
if self._signal_function:
8581
self._signal_function(self)
8682

0 commit comments

Comments
 (0)