Repository navigation
Conversation
2 tasks done
anth-volk
added this pull request to stack #3888
October 13, 2026 17:00
anth-volk
removed this pull request from stack #3888
October 13, 2026 19:26
anth-volk
added this pull request to stack #3917
October 13, 2026 19:26
anth-volk
force-pushed
the
ruff-exceptions
branch
2 times, most recently
from
October 14, 2026 16:43
b9d05f4 to
da23890
Compare
anth-volk
force-pushed
the
ruff-exceptions
branch
from
October 14, 2026 16:59
da23890 to
511b12c
Compare
Apply ruff's EM101/EM102 fix: every raise that built its message inline now assigns it to msg first, which also clears TRY003. Message text is unchanged; an AST check inlined each msg back into its raise and found the trees identical, and confirmed no function gaining msg already read, bound or closed over another msg. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The checks that get_spm_capability, validate_worker_spm, validate_worker_result, normalize_spm_selection and calculation_spm_receipt wrapped in try blocks now live in helpers, so each handler still receives the same exceptions (TRY301). A failed isinstance check raises TypeError where every handler of it already treats TypeError and ValueError alike, or nothing catches it (TRY004). It stays ValueError where calculation_spm_receipt certifies only ValueError or a Pydantic validator reports it, and RuntimeError where the bundle tests expect it, each with an inline reason. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The household, policy, report output and simulation services raise InvalidHouseholdIdError, InvalidPolicyIdError, InvalidReportOutputIdError and InvalidSimulationIdError instead of a bare Exception (TRY002). Each subclasses Exception directly, so every existing except Exception and the Flask generic error handler still catch them, with the same message. The budget-window method moves its stored-failure replay and its submission-claim loop into helpers, so their raises leave the logging try block (TRY301), and the reform-impact persistence handlers re-raise with a bare raise (TRY201). Budget-window SPM output whose annual impacts are not a list of objects raises TypeError, which its only handler already treats like ValueError (TRY004). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The report-output and simulation PATCH routes check for "No fields to update" in a helper, so the BadRequest leaves the try block yet still reaches the same HTTPException re-raise (TRY301). The household calculation routes log a fixed message with the traceback instead of passing the exception object to logging.exception (TRY401); the traceback still ends with the exception and its message. The household create request's model validator keeps raising ValueError, which Pydantic reports as a 422, with an inline reason (TRY004). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
find-api-model-versions.py raises TypeError when the installed bundle manifest or its package mapping is not an object (TRY004). Nothing catches these errors: the script still exits with a traceback, so the bundle-update script fails exactly as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test that builds a raised ValueError now raises it in a helper, so the raise leaves the try block (TRY301) and the error keeps its traceback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reform normalizer's float() coercion now catches only TypeError, ValueError and OverflowError, the only errors float() raises for the JSON values a policy holds. Every other except Exception is a deliberate catch-all and keeps its behaviour with an inline reason: telemetry, logging and metric calls that must never fail a request or change a result, cache reads and writes that degrade to a miss or False, best-effort cleanup, the health probe, the search route's JSON 500, the committed-write mirror fallbacks, and the import-time version fallback (BLE001). The health probe also returns its result from an else block (TRY300). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Select flake8-blind-except (BLE), flake8-errmsg (EM) and tryceratops (TRY). Tests follow all three: their exemptions stay limited to S101, D1, ANN and PLR2004. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SPMValidationError takes a stable error code and then the client-facing message, so the 18 variables the EM fix named msg are renamed error_code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ten older suppressions, active now that BLE is enabled, used the "- reason" form; they now match every other suppression. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
api.quality.ruff-lint now lists the group 5 families, and the rendered rules page and AGENTS.md Rules block are regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#3918's _serialize_region_filter_value passes f-string messages straight to CatalogExtractionError, which EM102 and TRY003, enabled on this branch, report. Assign each message to msg first, as the rest of the extraction module does; the messages are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
force-pushed
the
ruff-exceptions
branch
from
October 14, 2026 18:08
511b12c to
6a51afc
Compare
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3912
Summary
Phase 1 step 1.8, group 5: exceptions and messages. Stacked on #3907.
selectgainsTRY,EMandBLE. All 1,337 findings at the base are fixed.raise(633 places). A script put every message back inline in both trees: all 122 files came out identical, so the message text is unchanged. It also found no clash with an existingmsgin any scope.SPMValidationErroris an error code, the hoisted variable is namederror_code, notmsg(18 places).tryblocks (TRY301 32, TRY300 1): each raise moves into a small helper, so a handler can't catch its own raise. Each handler still receives the same exceptions. The helpers live in the simulation entrypoint, the worker SPM client,spm, the economy service, the routes and one test.InvalidPolicyIdError, instead of bareException. Each subclassesExceptiondirectly, and Flask's generic handler still rendersstr(error), so responses are unchanged.TypeError, where nothing catches the old type specifically or the only handler treats both alike. 7 keep their type with a reason:ValueError.TypeErrorwould turn a validation error into a 500.spmchecks keepValueError, becausecalculation_spm_receiptcatches onlyValidationErrorandValueError.constants.pykeepsRuntimeError, which a test asserts.raise ebecomes a bareraisein the reform-impact persistence handlers.except Exceptioncatches (BLE001 38):country.pynow catches only the three errorsfloat()can raise.noqa: BLE001comments, inert until now, used the- reasonstyle. They now use the standard# reasonform.str(error); the traceback still ends with the exception and its message. Elsewhere, tracebacks gain a frame for each new helper and lose the extraraise eline./v2/openapi.jsonpreview and the legacy spec.api.quality.ruff-lintnow listsBLE,EMandTRY. The shared rules tool needed no changes and is still byte-identical with sim (tool sha256db83d5ad2aa4). Sim's group 5 is Enable ruff exception rules (TRY, EM, BLE) policyengine-sim-api#783.Testing
pytest tests/unit tests/contract, to_refactor and the dedupe integration test (themake testset) at this branch's tip: 2,420 passed.make typecheck-v2is clean. mypy on the 15 changed files outside that gate gives the same output as the base.ruff checkandruff format --check(0.15.12) are clean repo-wide.CI complete, which fails and says why (step 0.7, Make CI enforcement trustworthy before the rules registry #3887). Its full run starts once the PRs below it merge.🤖 Generated with Claude Code