-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
opencv-python stubs #8879
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
opencv-python stubs #8879
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
- Can't parse 'org_'. Input argument doesn't provide sequence protocol
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I can see a lot of work's gone into this.
Just a few questions from skimming through:
stubs/opencv-python/cv2/__init__.pyi
Outdated
from cv2 import data as data, gapi as gapi, mat_wrapper as mat_wrapper, misc as misc, utils as utils, version as version | ||
from cv2.cv2 import * | ||
|
||
__all__: list[str] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit weird. __all__
is empty, but there's nonetheless a bunch of stuff that should be considered re-exported from the module? 🧐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__all__
is also empty in the source code and at runtime.
If __all__
is empty, should it be omitted?
Btw, cv2 adds a bunch of code and modules dynamically, not sure if that's why they have an empty __all__
there..
and Updated with preliminary PR comments
This comment has been minimized.
This comment has been minimized.
- _WrappedMat private - Algorithm base __init__ - VideoCapture - Method overload missing self arg - python/mypy#8881
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Adding the "DO-NOT-MERGE" label, as I just noticed the note at the top of the PR description :) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Some update: work has started again on opencv stub generation in opencv/opencv#20370 . Hopefully this here PR never gets to be merged, or a slightly different version of it for older openCV support (as I've already mentioned, some people, myself included, are stuck on 4.5 for different reasons). Keeping this here as a draft as it is a very useful comparison point (manual stubs vs automated stubs) to eventually get the wip official generated stubs as accurate as possible. |
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: streamlit (https://github.com/streamlit/streamlit)
+ lib/tests/streamlit/elements/image_test.py:21: note: ... from here:
- lib/tests/streamlit/elements/image_test.py:21:1: error: Cannot find implementation or library stub for module named "cv2" [import]
|
Given the recent issues with SQLAlchemy2, I no longer think it would be wise to backport cv2 types, even if they're available right now from a github install. And thanks to opencv-python being updated with type generation before opencv 4.8, it means users will already have access to types (even if early versions) in opencv4.7 by installing from github. |
ready for review, but do not merge until #5768 . numpy is too fundamental for this stub, and merging as-is will cause lots of issues when trying to use it with pyright strict typing
(I could make an ndarray protocol with all of its properties and methods, but I'd rather wait)
cv2/cv2.pyi
.dts
todst
list
params toSequence
andtuple
params to aliases that includeSequence
self
parameterAs noted in
METADATA.toml
, the stub is stuck on opencv-python v4.5 until opencv/opencv-python#676 is fixed (import cv2.cv2
causes an error).cv2/cv2.pyi
is incomplete, massive and you might just wanna skim over it. But everything else should get a proper look and is meant to be complete.For later / Not in this PR:
Fix unspecified encoding causingUnicodeDecodeError
with utf-8 chars on Windows incheck_new_syntax.py
(Specify file encoding #8882) andFlake8-pyi
(Specify encoding in open PyCQA/flake8-pyi#296)# incomplete
signatures using docstrings from thehelp()
method.