feat(audit): add dunder-method bare-raise heuristic (Phase 11)
Bare raise AttributeError/NameError in __getattr__, __getattribute__, __setattr__, __delattr__ is the canonical Python dunder-method programmer-error pattern. Reclassify as INTERNAL_PROGRAMMER_RAISE. Reclassifies 6 sites across 3 files: - src/gui_2.py: L778, L781 (was 2 INTERNAL_RETHROW) - src/app_controller.py: L1283, L1309 (was 4 INTERNAL_RETHROW) - src/models.py: L267 (was 1 INTERNAL_RETHROW) Per conductor/code_styleguides/error_handling.md lines 625-690 (Re-Raise Patterns): bare raises are reserved for programmer errors / impossible states / canonical dunder method behaviors. Phase 11 result_migration_gui_2_20260619.
This commit is contained in:
@@ -1028,6 +1028,21 @@ class ExceptionVisitor(ast.NodeVisitor):
|
|||||||
f"Compliant: `raise {exc_short}` inside `if <var> is None:` is the canonical validation/precondition-check pattern (per result_migration_review_pass_20260617).",
|
f"Compliant: `raise {exc_short}` inside `if <var> is None:` is the canonical validation/precondition-check pattern (per result_migration_review_pass_20260617).",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Heuristic added by result_migration_gui_2_20260619 (Phase 11):
|
||||||
|
# Bare `raise AttributeError(...)` or `raise NameError(...)` in a dunder
|
||||||
|
# method (__getattr__/__getattribute__/__setattr__/__delattr__) is the
|
||||||
|
# canonical Python dunder-method programmer-error pattern. Per the
|
||||||
|
# styleguide "Re-Raise Patterns" (error_handling.md lines 625-690), bare
|
||||||
|
# raises are reserved for programmer errors / impossible states /
|
||||||
|
# canonical dunder method behaviors. The Python data-model contract for
|
||||||
|
# these dunders explicitly raises AttributeError when an attribute does
|
||||||
|
# not exist or is not settable.
|
||||||
|
if exc_short in {"AttributeError", "NameError"} and self._current_func_name() in {"__getattr__", "__getattribute__", "__setattr__", "__delattr__"}:
|
||||||
|
return (
|
||||||
|
"INTERNAL_PROGRAMMER_RAISE",
|
||||||
|
f"Compliant: `raise {exc_short}` in `{self._current_func_name()}` is the canonical dunder-method programmer-error pattern (per styleguide 'Re-Raise Patterns' and Phase 11 result_migration_gui_2_20260619).",
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
"INTERNAL_RETHROW",
|
"INTERNAL_RETHROW",
|
||||||
f"Review: `raise {exc_name}` in internal code. Confirm this is a programmer error (assertion) and not a runtime failure (which should be a Result).",
|
f"Review: `raise {exc_name}` in internal code. Confirm this is a programmer error (assertion) and not a runtime failure (which should be a Result).",
|
||||||
|
|||||||
Reference in New Issue
Block a user