Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type annotation and kwargs to run.io_bound and run.cpu_bound #227

Merged
merged 6 commits into from
Nov 12, 2024

Conversation

falkoschindler
Copy link
Contributor

As noticed by @denniswittich, IO- and CPU-bound functions in RoSys are missing type annotations for parameters and return values. Apart from that run.cpu_bound is missing kwargs.

While this PR adds both, it unveils several type errors in connection with run.cpu_bound and run.io_bound:

rosys/run.py:26: error: Missing return statement  [return]
rosys/run.py:28: error: Return value expected  [return-value]
rosys/run.py:46: error: Missing return statement  [return]
rosys/run.py:48: error: Return value expected  [return-value]
rosys/vision/usb_camera/usb_device.py:85: error: Incompatible types in assignment (expression has type "Awaitable[Any] | None", variable has type "tuple[bool, Mat | ndarray[Any, dtype[integer[Any] | floating[Any]]]]")  [assignment]
rosys/vision/usb_camera/usb_camera.py:92: error: Argument 2 to "io_bound" has incompatible type "ndarray[Any, Any]"; expected "list[ndarray[Any, Any]]"  [arg-type]
rosys/vision/usb_camera/usb_camera.py:94: error: Argument 1 to "cpu_bound" has incompatible type "Callable[[bytes, ImageRotation, Rectangle | None], bytes | None]"; expected "Callable[[bytes, ImageRotation, Rectangle | None], bytes]"  [arg-type]
rosys/vision/mjpeg_camera/mjpeg_camera.py:94: error: Argument 1 to "cpu_bound" has incompatible type "Callable[[bytes, ImageRotation, Rectangle | None], bytes | None]"; expected "Callable[[bytes, ImageRotation, Rectangle | None], bytes]"  [arg-type]

We should fix them before merging into main.

@falkoschindler falkoschindler added the enhancement New feature or request label Nov 7, 2024
@falkoschindler falkoschindler added this to the 0.19.0 milestone Nov 7, 2024
@falkoschindler
Copy link
Contributor Author

Ok, now there's only one mypy issue left related to an ndarray in usb_camera.py.
@NiklasNeugebauer Maybe you can have a look. 🙏

@falkoschindler falkoschindler marked this pull request as ready for review November 7, 2024 11:17
@NiklasNeugebauer
Copy link
Contributor

NiklasNeugebauer commented Nov 7, 2024

@falkoschindler I was unable to figure out which type the result of capture.read might have in this case.
I doubt it is a list, but it might be an array with an extra dimension that is removed here by calling [0].
The related code section for handling raw MJPEG images is not used right now since the initial parameter checks are never executed. I was looking a little into the UsbDevice yesterday. It needs work at a lot of places, but nothing really critical, so maybe we can just talk about it in the next weekly.

For now, I decided to keep the current behavior, but execute it in the device and then deliver the raw bytes from there.

@falkoschindler falkoschindler merged commit bbc5b98 into main Nov 12, 2024
5 checks passed
@falkoschindler falkoschindler deleted the run-typing branch November 12, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants