Skip to content

Conversation

VadimLevin
Copy link
Contributor

@VadimLevin VadimLevin commented Jun 14, 2023

Provide cv2.typing aliases at runtime.

  • cv2.typing is generated as __init__.py instead of __init__.pyi
  • built-in generics are changed to types from built-in typing module to handle Python versions < 3.9
  • Type aliases comments are changed to doc strings. Example:
import typing IntPointer = int """Represents an arbitrary pointer""" MatLike = typing.Union[cv2.mat_wrapper.Mat, numpy.ndarray[typing.Any, numpy.dtype[numpy.generic]]] MatShape = typing.Sequence[int] Size = typing.Sequence[int] """Required length is 2"""

Resolves: #23782
Resolves: #23778

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
@VadimLevin VadimLevin added this to the 4.8.0 milestone Jun 14, 2023
@VadimLevin VadimLevin requested a review from asmorkalov June 14, 2023 15:03
@VadimLevin VadimLevin self-assigned this Jun 14, 2023
@VadimLevin
Copy link
Contributor Author

@Avasam take a look please

@VadimLevin VadimLevin force-pushed the dev/vlevin/runtime-typing-module branch from 7a889eb to 8e86384 Compare June 14, 2023 17:09
@Avasam
Copy link
Contributor

Avasam commented Jun 14, 2023

I can't really test anything until at least tomorrow.
But from the PR description and a cursory glance at the changes this looks good.

Copy link
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@asmorkalov
Copy link
Contributor

Tested manually with Ubuntu and Python 3.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment