Repository navigation
Pass target type to format_exception for noteless failures - #832
Closed
Aschenbath wants to merge 1 commit into
Closed
Aschenbath wants to merge 1 commit into
Aschenbath wants to merge 1 commit into
Conversation
Author
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.
transform_errorcould only pass a target type toformat_exceptionfor failures inside classes and iterables, where the generated hooks attach notes carrying the type. A failure at the top level — most commonly structuring a bare primitive — reached the formatter with no type:Changes:
cattrs.errorsgains aTypeValidationNote(exported fromcattrslike the other notes): a note carrying the target type, modeled onAttributeValidationNote/IterableValidationNote.BaseConverter.structure()attaches such a note when the dispatched hook raises,detailed_validationis on, and the exception carries no notes yet — so the note records the innermost failing target (the method is also called recursively, e.g. by union disambiguation, and only the first, noteless failure point attaches one). Withdetailed_validation=Falsenothing is attached.transform_errorconsults the new note wherever it previously passedNonetoformat_exception(the bare-exception branch and the note-less members of class/iterable groups), so customformat_exceptionimplementations also receive the type.Tests: new cases in
tests/test_v.pycover top-levelint/floatfailures, a customformat_exceptionreceiving the type, and thedetailed_validation=Falsebehavior.test_v.py+test_errors.py: 33 passed. Full test suite: 1087 passed, 15 xfailed, 20 skipped; the only 2 failures aretest_preconf.pytomllib tests, which fail identically on unmodified upstream main in this environment (anAttributeErrorfrom the installed toml library, unrelated to this change). A changelog entry is added underNEXTin HISTORY.md.Fixes #401