1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Fix Python bindings when optional modules like gapi are disabled

Fix two issues that cause `import cv2` to fail when building with
-DBUILD_opencv_gapi=OFF:

1. In `has_all_required_modules()`, the function parameter `type_node`
   was ignored in favor of the enclosing scope's loop variable `node`.
   This works by accident when called as `has_all_required_modules(node)`
   but is incorrect — the parameter should be used directly.

2. In `__load_extra_py_code_for_module()`, only `ImportError` was
   caught. When a stale gapi submodule directory exists from a previous
   build, gapi/__init__.py raises `AttributeError` (not `ImportError`)
   because it tries to access C++ bindings that don't exist. Now catches
   both exception types for defense-in-depth.

Refs: #26098
This commit is contained in:
Pavel Guzenfeld
2026-03-15 23:21:42 +02:00
parent 00833f98d0
commit 95ab7149fe
2 changed files with 2 additions and 2 deletions
@@ -708,7 +708,7 @@ def _generate_typing_module(root: NamespaceNode, output_path: Path) -> None:
"""
def has_all_required_modules(type_node: TypeNode) -> bool:
return all(em in root.namespaces for em in node.required_modules)
return all(em in root.namespaces for em in type_node.required_modules)
def register_alias_links_from_aggregated_type(type_node: TypeNode) -> None:
assert isinstance(type_node, AggregatedTypeNode), \