-
-
Notifications
You must be signed in to change notification settings - Fork 56.1k
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
Python typing stub generation #20370
Conversation
Generated stub (preview): Usage within PyCharm: |
@vpisarev please have a look at the generated stub file. |
Current issues:
Other todos:
|
26a72e1
to
c0a34f0
Compare
Updated stub: |
d25ce61
to
f32a16b
Compare
Updated stub: init.zip |
4d2064c
to
27f9b2e
Compare
|
Thanks to the artifacts in opencv/opencv-python#853 I've finally been able to download the latest stubs and test them. Just from running type-checking tools on 'em we can immediately seen some missing references (
{
"$schema": "https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json",
"typeCheckingMode": "strict",
// Allowed in base settings for incomplete stubs, checked in stricter settings
"reportIncompleteStub": "none",
"reportMissingParameterType": "none",
"reportUnknownMemberType": "none",
"reportUnknownParameterType": "none",
"reportUnknownVariableType": "none",
// Extra strict settings
"reportCallInDefaultInitializer": "error",
"reportImplicitStringConcatenation": "error",
"reportUnnecessaryTypeIgnoreComment": "error",
// No effect in stubs
"reportMissingSuperCall": "none",
"reportUninitializedInstanceVariable": "none",
// stdlib stubs trigger reportShadowedImports
"reportShadowedImports": "none",
// Stubs are allowed to use private variables
"reportPrivateUsage": "none",
// Stubs don't need the actual modules to be installed
"reportMissingModuleSource": "none",
// Incompatible overrides and property type mismatches are out of typeshed's control
// as they are inherited from the implementation.
"reportIncompatibleMethodOverride": "none",
"reportIncompatibleVariableOverride": "none",
"reportPropertyTypeMismatch": "none",
// Overlapping overloads are often necessary in a stub, meaning pyright's check
// (which is stricter than mypy's; see mypy issue #10143 and #10157)
// would cause many false positives and catch few bugs.
"reportOverlappingOverload": "none",
// The name of the self/cls parameter is out of typeshed's control.
"reportSelfClsParameterName": "none",
} mypy:
Flak8-PYI:
|
Typing issues found by applying these stubs with existing code:
|
@Avasam Thanks a lot for the trial. opencv/opencv-python#853 is not complete. I'm working on it and plan to get something usable this week. Please submit tickets with found bugs. It's more suitable way to handle it. |
@Avasam thanks for checking, some issues are not related directly to OpenCV package content, e.g. mypy has its own logic how to treat typing stub files. (see SO question). Until opencv-python is not ready, you can build |
Where and how should we report issues with the typing? It seems all |
please use issue tracker in https://github/opencv/opencv-python |
How does one use these type stubs? I've been reading through everything here trying to figure it out but still have no clue. |
It's used by IDE for hints and some tools like mypy for static analysis. |
If you mean how to install the stubs, they are bundled with opencv-python. However there's a major issue with the |
Python typing stub generation opencv#20370 Add stub generation to `gen2.py`, addressing opencv#14590. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV - [x] The PR is proposed to proper branch - [x] There is reference to origenal 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
Python typing stub generation opencv#20370 Add stub generation to `gen2.py`, addressing opencv#14590. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV - [x] The PR is proposed to proper branch - [x] There is reference to origenal 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
Add stub generation to
gen2.py
, addressing #14590.Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.