Remaining bare `except:` / swallowed exceptions in tests/ and src/ (Codacy + hidden failures)
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 45/100
- Issue 類型
- 重構
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- python
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- Python
- 星號
- 225
- 分支
- 35
- 平均合併
- 1 天 20 小時
- 30 天內合併 PR
- 34
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
petercorke/machinevision-toolbox-python 的其他 Issue
-
難度 3/5 1-2 天 新手友好度 76/100
petercorke/machinevision-toolbox-python#160 ·
維護者通常 1 天內回覆
-
tech-debt
難度 4/5 3-5 天 新手友好度 39/100
petercorke/machinevision-toolbox-python#159 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 42/100
petercorke/machinevision-toolbox-python#157 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 48/100
petercorke/machinevision-toolbox-python#152 ·
維護者通常 1 天內回覆
-
ROSBag: RealSense bags have a 4-byte depth-units trailer that is guessed, not parsed可能重新可做 關聯的 PR 已關閉且未合併。 未關閉bug help wanted
難度 5/5 一週以上 新手友好度 25/100
petercorke/machinevision-toolbox-python#151 ·
維護者通常 1 天內回覆
查看 petercorke/machinevision-toolbox-python 的全部 Issue
相似的 Issue
-
factory
難度 2/5 1-3 小時 新手友好度 78/100
Arize-ai/phoenix#17420 · 1 則留言 · 1 個 reaction ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 84/100
FireDynamics/LEDSmokeAnalysis#176 ·
維護者通常 1 天內回覆
-
PC
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
dependencies
難度 2/5 1-3 小時 新手友好度 68/100
dlt-contrib/dlt-filesystem#51 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆