Repository navigation
fix(toon): raise ToonDecodeError, not ValueError, on invalid escapes - #209
Open
rahul05ranjan wants to merge 1 commit into
Open
rahul05ranjan wants to merge 1 commit into
rahul05ranjan wants to merge 1 commit into
Conversation
_unescape raised a bare ValueError for invalid escape sequences, so the nine conformance cases in Oaklight#198 escaped callers writing except ToonDecodeError — the type the module's own docstrings promise. _unescape is decode-only (its two callers already raise ToonDecodeError for sibling failures), so the raise sites move to the contract type and the baseline shrinks by those nine. Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
This branch has not been 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.
What
_unescapenow raisesToonDecodeErrorinstead of a bareValueErrorfor invalid escape sequences and a trailing backslash, and the conformance baseline shrinks by the nine IDs from #198.Why
The module's contract — its docstrings and the
Raises:sections, and what the conformance gate enforces onshouldErrordecode cases — isToonDecodeError. A caller writingexcept ToonDecodeErrordid not catch these nine escapes; they leaked out as a genericValueError:All nine trace to the two
raise ValueErrorsites in_unescape. That helper is decode-only — its only callers are_parse_primitiveand_parse_key, which already raiseToonDecodeErrorfor sibling malformed-string cases ("Unterminated string", "Unterminated quoted key"), so the raise sites simply move to the contract type.ToonDecodeErrordoes not subclassValueError, and noexcept ValueErrorhandler in the module wraps these paths, so nothing else changes behaviour.Changes
toon/toon.py: the two raise sites in_unescapemove fromValueErrortoToonDecodeError.toon/conformance_baseline.json:--update-baselineremoves the nine IDs;passing_total350 → 359.toon/test_toon_decode_errors.py: new no-dependency tests pinning the contract directly — parametrized invalid escapes (including the quoted-key and non-strict cases), the trailing-backslash case, and thatToonDecodeErroris not aValueErrorsubclass.Verification
shouldErrordecode cases raisingValueError(scanned all 404 decode fixtures: exactly 9, no extras).pytest toon/test_toon_conformance.py: 6 passed on the branch (the gate itself demanded the baseline shrink —test_baseline_entries_still_failfails until the nine IDs are removed, then passes).pytest toon/test_toon_decode_errors.py toon/test_toon_conformance.py: 14 passed.toon/test_toon_correctness.pyis skipped here (needs thetoon_formatreference package, not installed in this environment).make lint(ruff/ty/complexipy) was not runnable locally; the diff is two changed raise sites plus tests written to match the surrounding style.Fixes #198