Fix misleading error messages in conversions dispatch fallbacks - #3856
Open
takayoshi-makabe wants to merge 1 commit into
Open
Fix misleading error messages in conversions dispatch fallbacks#3856takayoshi-makabe wants to merge 1 commit into
takayoshi-makabe wants to merge 1 commit into
Conversation
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.
Rationale for this change
The
singledispatchfallbacks inconversions.pydescribe the wrong operation, so an unregistered type produces a message that sends you looking in the wrong place. Passing a type with no registered implementation to each of the five entry points today:This reworks the three to follow the shape
from_bytesalready uses, so each names the operation it performs and the value it rejected:partition_to_pyandfrom_bytesare already accurate and are left alone.One small change beyond the strings:
to_bytestakes its value parameter asvalueinstead of_so the message can include it, matching the other four. It is rendered with!r, likefrom_bytes, because the parameter also acceptsbytes.Are these changes tested?
Yes.
test_raise_on_unregistered_typeasserted the oldto_byteswording, so it is updated.to_jsonandfrom_jsonhad no fallback coverage at all — which is how the copied text survived — so cases for both are added and all five entry points are now covered.Are there any user-facing changes?
Only the text of these
TypeErrormessages. No behaviour changes: the same inputs raise the same exception type in the same places.