Repository navigation
Pass the target type to format_exception for standalone values - #834
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
|
Closing this as a duplicate — #832, opened a little earlier, implements the same change (passing the target type to |
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.
With detailed validation, failures inside classes and iterables carry
AttributeValidationNote/IterableValidationNotes, sotransform_errorcan hand the target type toformat_exception. A failure structuring a standalone value — the common case being a primitive likeintat the top level — carried nothing, so the formatter receivedNoneand produced a bare "invalid value" with no type.cattrs.ValueValidationNote, attached byBaseConverter.structurewhen detailed validation is on and a failure escapes without a more specific note and is not a grouped validation error.transform_errornow reads that note in its standalone branch and passes the type to the formatter:converter.structure("x", int)now yields "invalid value for type, expected int @format_exception's "expected an iterable" special case forTypeErrors now applies whenever the message matches, not only when no type is known. Previously aList[int]field given a non-iterable said "expected List" while the top-level equivalent said "expected an iterable"; the two now agree.Tests: three new tests in
tests/test_v.py(default formatter output forint/float, a custom formatter receiving the type, and no note without detailed validation). The full test suite passes on this machine (1050 tests acrosstests/andtests/strategies/); the only exceptions are three version-gated modules (test_frozendicts_315.py,test_sentinels_315.py,test_gen_dict_649.py) that fail to import on Python 3.12 on unmodified upstream as well.Fixes #401