Skip to content

feat: re-export cv2.typing module as typing#24356

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
VadimLevin:dev/vlevin/typing-re-export
Oct 4, 2023
Merged

feat: re-export cv2.typing module as typing#24356
asmorkalov merged 1 commit intoopencv:4.xfrom
VadimLevin:dev/vlevin/typing-re-export

Conversation

@VadimLevin
Copy link
Copy Markdown
Contributor

@VadimLevin VadimLevin commented Oct 3, 2023

Import Python typing module as _typing to avoid name clashes.

resolves opencv/opencv-python#901
resolves #24352

Changes:

# __init__.pyi

# Import section update

import typing as _typing

# Re-export section update

from cv2 import typing as typing

# Python `typing` module usage update

@_typing.overload
def solveLP(Func: UMat, Constr: UMat, z: UMat | None = ...) -> tuple[int, UMat]: ...

Test file content:

import typing
import cv2
import cv2.typing

if typing.TYPE_CHECKING:
    reveal_type(cv2.typing.MatLike)
    reveal_type(cv2.imdecode)
    reveal_type(cv2.cuda.unregisterPageLocked)

Command: mypy test.py

Output:

test.py:6: note: Revealed type is "typing._SpecialForm"
test.py:7: note: Revealed type is "Overload(def (buf: Union[cv2.mat_wrapper.Mat, numpy.ndarray[Any, numpy.dtype[numpy.generic]]], flags: builtins.int) -> Union[cv2.mat_wrapper.Mat, numpy.ndarray[Any, numpy.dtype[numpy.generic]]], def (buf: cv2.UMat, flags: builtins.int) -> Union[cv2.mat_wrapper.Mat, numpy.ndarray[Any, numpy.dtype[numpy.generic]]])"
test.py:8: note: Revealed type is "def (m: Union[cv2.mat_wrapper.Mat, numpy.ndarray[Any, numpy.dtype[numpy.generic]]])"

FYI: @Avasam, @rassie

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

Import Python typing module as `_typing` to avoid name clashes.
Copy link
Copy Markdown
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 asmorkalov merged commit 670c52f into opencv:4.x Oct 4, 2023
@asmorkalov asmorkalov mentioned this pull request Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alias typing (stdlib) in cv2/__init__.pyi and explicitely re-export cv2.typing Module "cv2" does not explicitly export attribute "typing"

2 participants