Skip to content

Python type stubs: Class cv2.error is missing properties #23925

@Avasam

Description

@Avasam

System Information

OpenCV python: opencv-python-headless==4.8.0.74
Operating System / Platform: 10.0.19045 Build 19045
Python version: 3.9.13

Detailed description

Class cv2.error is currently typed as:

class error(Exception): ...

but should be something like:

class error(Exception):
    code: int
    err: str
    file: str
    func: str
    line: int
    msg: str

(They are technically ClassVars, but would be None)

As inspected with:

>>> import cv2
>>> error_dir = dir(cv2.error)
>>> exception_dir = dir(Exception)
>>> [x for x in error_dir if x not in exception_dir]
['__module__', '__weakref__', 'code', 'err', 'file', 'func', 'line', 'msg']

>>> try:
...   cv2.VideoCapture().read("aaa")
... except cv2.error as error:
...   print(type(error.code), type(error.err), type(error.file), type(error.func), type(error.line), type(error.msg))
...
<class 'int'> <class 'str'> <class 'str'> <class 'str'> <class 'int'> <class 'str'>

Steps to reproduce

Actual usage example:
image

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions