Skip to content

Commit af2f39e

Browse files
pantheraleo-7davidplowman
authored andcommitted
add comprehensive static typing of return types of user-facing functions; resolve remaining type checker errors
1 parent 0c59977 commit af2f39e

File tree

5 files changed

+181
-239
lines changed

5 files changed

+181
-239
lines changed

picamera2/job.py

Lines changed: 9 additions & 14 deletions
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,11 @@ 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]]]], signal_function=None
31+
):
3732
self._functions = functions
3833
self._future = Future()
3934
self._future.set_running_or_notify_cancel()
@@ -80,7 +75,7 @@ def signal(self) -> None:
8075
assert not self._functions, "Job not finished!"
8176

8277
if not self._future.done():
83-
self._future.set_result(cast(T, self._result))
78+
self._future.set_result(self._result)
8479
if self._signal_function:
8580
self._signal_function(self)
8681

0 commit comments

Comments
 (0)