Skip to content
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

Closed
wants to merge 38 commits into from
Closed

opencv-python stubs #8879

wants to merge 38 commits into from

Conversation

Avasam
Copy link
Sponsor Collaborator

@Avasam Avasam commented Oct 11, 2022

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)

As 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:

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

- Can't parse 'org_'. Input argument doesn't provide sequence protocol
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Avasam Avasam marked this pull request as ready for review October 12, 2022 19:00
@github-actions

This comment has been minimized.

Copy link
Member

@AlexWaygood AlexWaygood left a 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:

Comment on lines 1 to 4
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] = []
Copy link
Member

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? 🧐

Copy link
Sponsor Collaborator Author

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..

stubs/opencv-python/cv2/cv2.pyi Outdated Show resolved Hide resolved
stubs/opencv-python/cv2/cv2.pyi Outdated Show resolved Hide resolved
stubs/opencv-python/cv2/cv2.pyi Outdated Show resolved Hide resolved
stubs/opencv-python/cv2/cv2.pyi Outdated Show resolved Hide resolved
stubs/opencv-python/cv2/gapi/__init__.pyi Show resolved Hide resolved
and Updated with preliminary PR comments
@github-actions

This comment has been minimized.

- _WrappedMat private
- Algorithm base __init__
- VideoCapture
- Method overload missing self arg
- python/mypy#8881
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member

Adding the "DO-NOT-MERGE" label, as I just noticed the note at the top of the PR description :)

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Avasam
Copy link
Sponsor Collaborator Author

Avasam commented Jan 2, 2023

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.

@Avasam Avasam marked this pull request as draft January 2, 2023 20:11
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2023

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]

@Avasam
Copy link
Sponsor Collaborator Author

Avasam commented Jun 10, 2023

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.

@Avasam Avasam closed this Jun 10, 2023
@Avasam Avasam deleted the opencv2 branch June 10, 2023 18:09
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.

None yet

3 participants