Skip to content

Prefer using TYPE_CHECKING condition in cv2.typing module#23972

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
Avasam:partially-unknown-mat
Jul 12, 2023
Merged

Prefer using TYPE_CHECKING condition in cv2.typing module#23972
asmorkalov merged 1 commit intoopencv:4.xfrom
Avasam:partially-unknown-mat

Conversation

@Avasam
Copy link
Copy Markdown
Contributor

@Avasam Avasam commented Jul 11, 2023

Fixes an issue in #23838 that re-introduced #23780 for NumPyArrayGeneric, NumPyArrayFloat32, NumPyArrayFloat64 and all their aliases/subtypes/unions. As well as supporting generic static hints in python 3.8.

Read #23927 (comment) for the full explanation.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original 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

@Avasam
Copy link
Copy Markdown
Contributor Author

Avasam commented Jul 11, 2023

CC @VadimLevin

# Same as cv2.typing.NumPyArrayGeneric, but avoids circular dependencies
if TYPE_CHECKING:
_NDArray = np.ndarray[Any, np.dtype[np.generic]]
_NumPyArrayGeneric = np.ndarray[Any, np.dtype[np.generic]]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could actually import cv2.typing here so that the types don't fall out of sync. But the alias would still be necessary to avoid circular dependencies.

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.

3 participants