refactor: add type annotations and improve type safety #1205
+204
−83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces significant improvements to type hinting as part of resolving issue #1192.
dispatch_functions
, ensuring that it now correctly propagates return types.Job
class into a generic type.capture_array
,capture_image
, andcreate_video_configuration
.assert
statements.pyright
configuration: disabled thereportUnknownMemberType
warning, resulting in fewer but more meaningful warnings being displayed.While the PR mainly focuses on typing improvements with no logical changes, there's a minor fix in
Job.cancel()
:Before:
Now:
This change ensures that
set_exception
is always given an instance ofCancelledError
, aligning withconcurrent.futures.Future
's expectations. The previous version would have raised aTypeError: exceptions must be derived from BaseException when raised
if it were ever encountered at runtime. This fix does not alter any behavior but ensures correctness.P.S. I didn't plan for this to be so extensive, but... it turned into a rabbit hole.