Repository navigation
refactor: every raise inside except chains with from - #25
Merged
Merged
Conversation
pytest.ini sets filterwarnings = error: a deprecation in this code or in a dependency fails the run instead of scrolling past in the summary. Both CI test jobs start the interpreter with -X warn_default_encoding, so a text read without an explicit encoding fails too. Set on the interpreter rather than in the job's env so Poetry's own process stays quiet. The suite was already clean under both flags with dependencies included (140 passed); a sanity test with a stray DeprecationWarning fails as intended. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The 13 re-raises the bugbear audit (B904) found now say what they are. `from e` where the new error translates the caught one: the integer and log-format parsers and the algorithm lookup in config.py, the rate-limit syntax check in limiter.py, the TOML read in scripts/release.py, the profile URL validator in schemas/user.py, IntegrityError to IdentifierTakenError in services/users.py, and PyJWT errors to the 401 in auth.py. `from None` for the four generic 500s in routers/users.py, whose cause is already logged with logger.exception and must not reach the client. No response changes; tracebacks now distinguish "caused by" from "raised while handling". AGENTS.md records the rule. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
The second of the two enhancements from yesterday's audit. Branched from
ci/warnings-are-errors(#24) so the changelog entries do not conflict; merge #24 first.Why
A
raiseinside anexceptblock withoutfromleaves Python to guess the relation between the two errors; the traceback then says "During handling of the above exception, another exception occurred", which is wrong for a deliberate translation and noisy for an error that was already logged. PEP 3134 chaining states it. ruff's bugbear rule B904 found 13 such sites; it now finds none.Changes
from e, the new error translates the caught one: the integer and log-format parsers and the algorithm lookup inconfig.py, the rate-limit syntax check inlimiter.py, the TOML read inscripts/release.py, the profile URL validator inschemas/user.py,IntegrityErrortoIdentifierTakenErrorinservices/users.py(twice), PyJWT errors to the 401 inauth.py.from None, the cause is already logged and must not reach the client: the four generic 500 responses inrouters/users.py, each preceded bylogger.exception.AGENTS.mdErrors rule gains the convention; changelog entry (refactor: every raise inside except chains with from #25).No response body or status changes.
Verification, local on Python 3.15.0 with PostgreSQL 17
black, flake8, mypy clean;
ruff check --select B904reports nothing (run once withuvx, not added to the project); the exact CI command from #24 (python -X warn_default_encoding -m pytest): 140 passed, no warnings. Sanity:minimum_secret_bytes("none")raises aValueErrorwhose__cause__is theKeyError.🤖 Generated with Claude Code