Remaining bare `except:` / swallowed exceptions in tests/ and src/ (Codacy + hidden failures)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- computer-vision, devtools, testing-qa
Hướng nghiên cứu
Start with #114's PR description and the listed files: tests/test_camera.py, tests/base/test_base_color.py, tests/test_ros.py, tests/conftest.py, and the named src locations. Run each protected test snippet on OpenCV 4 and 5, then review the exception sites and mutation-check that tests fail when behavior is broken. Done means the findings are addressed in focused PRs, the color.py message has a test, and Ruff rules E722, BLE001, and S110 can be enabled.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Follow-up to #51 / #114, which fixed the bare except: pass pattern in tests/test_image_point_features.py. Inventory of what remains as of 2026-10-03 (main at 770a031a). These are likely contributing to the Codacy B grade (Pylint/Pyflakes bare-except and try/except/pass/W0702/W0703-type findings, see #41) and, in tests, hide real failures.
Why it matters
In tests, a bare except: also swallows the AssertionError from assert*, so the test can never fail. Fixing the same pattern in #114 showed that several of those tests had been calling APIs that don't exist (Image.SURF, corners, getpixel, concat), so expect similar findings here: fix by running each snippet unprotected on OpenCV 4 and 5, rewriting against the real API with direct assertions, and mutation-checking that the test now fails when the code is broken (see #114's PR description for the method).
tests/
| File | bare except: |
except Exception + pass/continue |
|---|---|---|
tests/test_camera.py |
11 | 8 |
tests/base/test_base_color.py |
3 | 1 |
tests/test_ros.py |
0 | 3 |
tests/conftest.py |
0 | 2 (probably legitimate GUI-suppression; review rather than blanket-remove) |
src/
| Location | Issue | Suggested fix |
|---|---|---|
base/color.py:966 and :976 (rgb2xyz-style white/primaries lookup) |
bare except: around a dict lookup, then raise ValueError("unknown white value, must be one of" ", ".join(...)). Real bug: the two adjacent string literals concatenate first, so ", ".join(...) uses the whole sentence as the separator; the error message is garbled. |
except KeyError: and build the message with an f-string: f"unknown white value, must be one of {', '.join(_whites)}", plus a test that checks the message |
base/findpeaks.py:119 |
bare except: around Polynomial.fit, then print + continue |
catch the specific exceptions Polynomial.fit raises for a neighbourhood falling off the data; use warnings.warn rather than print |
base/imageio.py:1033 (set_window_title) |
bare except: pass |
except (AttributeError, RuntimeError): (backends without a window manager) |
Camera.py, ImageProcessing.py, base/imageio.py |
one except Exception: pass/continue each |
review each: narrow the exception type or log |
Suggested approach
Separate small PRs: (1) color.py message bug + test (src, real fix), (2) other src sites, (3) tests/test_camera.py, (4) tests/base/test_base_color.py and the rest. Add E722 (bare except) and BLE001/S110 (try-except-pass) to the ruff rule set once clean so it can't regress (see the typing/lint cluster, #40/#41).
Related: #41, #51, #113
- Ngôn ngữ chính
- Python
- Star
- 223
- Fork
- 30
- Merge trung bình
- 1 giờ 4 phút
- Pull request đã merge (30 ngày)
- 9
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của petercorke/machinevision-toolbox-python
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
petercorke/machinevision-toolbox-python#125 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tech-debt
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
petercorke/machinevision-toolbox-python#122 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tech-debt
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
petercorke/machinevision-toolbox-python#119 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tech-debt
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
petercorke/machinevision-toolbox-python#117 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tech-debt
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 62/100
petercorke/machinevision-toolbox-python#113 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của petercorke/machinevision-toolbox-python
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
awslabs/visual-asset-management-system#414 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug v1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
modelcontextprotocol/python-sdk#3670 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
aicell-lab/bioengine#232 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
modelscope/evalscope#1836 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100