Closed
Description
Expected behaviour
Type hints (e.g. with mypy
) work properly on cv2.imdecode
Actual behaviour
cv2.imdecode
return values resolve to Any
.
Steps to reproduce
- create a clean project with
opencv-python-headless
4.8.0.76 andmypy
1.5.1 - add a
main.py
with the following code:
import cv2
reveal_type(cv2.typing.MatLike)
reveal_type(cv2.imdecode)
- run
mypy
onmain.py
- observe the following:
main.py:3: error: Module "cv2" does not explicitly export attribute "typing" [attr-defined]
main.py:3: note: Revealed type is "Any"
main.py:4: note: Revealed type is "Overload(def (buf: Any, flags: builtins.int) -> Any, def (buf: cv2.UMat, flags: builtins.int) -> Any)"
It seems like the original override definition
@typing.overload
def imdecode(buf: cv2.typing.MatLike, flags: int) -> cv2.typing.MatLike: ...
@typing.overload
def imdecode(buf: UMat, flags: int) -> cv2.typing.MatLike: ...
can't resolve cv2.typing.MatLike
and replaces it by Any
. The reason seems to be the error message Module "cv2" does not explicitly export attribute "typing"
.
Issue submission checklist
- This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
- I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
- The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
- I'm using the latest version of
opencv-python
Metadata
Metadata
Assignees
Labels
No labels