From c3457f99f34cacd89db2c7a187b41abaa281a734 Mon Sep 17 00:00:00 2001 From: Matt Van Horn Date: Tue, 10 Mar 2026 22:55:36 -0700 Subject: [PATCH] Merge pull request #28621 from mvanhorn:osc/28528-fix-houghcircles-return-type imgproc: fix HoughCircles Python return type to allow None #28621 ### 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 another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] 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 ### Description Fixes https://github.com/opencv/opencv/issues/28528 `HoughCircles` returns `None` when no circles are found, but the auto-generated Python type stub declares the return type as `MatLike` without `None`. This causes type checkers (mypy/pyright) to miss potential `None` dereferences. **Fix:** Add `HoughCircles` to `NODES_TO_REFINE` in `api_refinement.py` using the existing `make_optional_none_return` helper - the same pattern already used for `imread` and `imdecode`. This contribution was developed with AI assistance (Claude Code). --- modules/python/src2/typing_stubs_generation/api_refinement.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/python/src2/typing_stubs_generation/api_refinement.py b/modules/python/src2/typing_stubs_generation/api_refinement.py index f92c5c8ce1..14d64e0cb8 100644 --- a/modules/python/src2/typing_stubs_generation/api_refinement.py +++ b/modules/python/src2/typing_stubs_generation/api_refinement.py @@ -457,6 +457,9 @@ NODES_TO_REFINE = { SymbolName(("cv", "fisheye"), (), "initUndistortRectifyMap"): make_optional_arg("D"), SymbolName(("cv", ), (), "imread"): make_optional_none_return, SymbolName(("cv", ), (), "imdecode"): make_optional_none_return, + SymbolName(("cv", ), (), "HoughCircles"): make_optional_none_return, + SymbolName(("cv", ), (), "HoughLines"): make_optional_none_return, + SymbolName(("cv", ), (), "HoughLinesP"): make_optional_none_return, # Fix for issue #28534: inRange should accept Scalar for lowerb and upperb SymbolName(("cv", ), (), "inRange"): make_matlike_or_scalar_arg("lowerb", "upperb"), }