gh-58857: Add error messages to bare assertions in wsgiref.validate#148291
Open
gaweng wants to merge 1 commit intopython:mainfrom
Open
gh-58857: Add error messages to bare assertions in wsgiref.validate#148291gaweng wants to merge 1 commit intopython:mainfrom
gaweng wants to merge 1 commit intopython:mainfrom
Conversation
…date Add descriptive error messages to all assertions in the wsgiref validator middleware that were previously missing them. This makes it much easier to diagnose WSGI compliance issues when using the validation middleware. The following assertions now include messages: - InputWrapper.read(): argument count and return type checks - InputWrapper.readline(): argument count and return type checks - InputWrapper.readlines(): argument count and return type checks - ErrorWrapper.write(): argument type check - WriteWrapper.__call__(): argument type check - check_headers(): header tuple length check
picnixz
reviewed
Apr 9, 2026
Member
picnixz
left a comment
There was a problem hiding this comment.
Honestly, I would rather prefer having a real TypeError/ValueError being raised instead of AssertionError here but it would unfortunately be backward incompatible :(
| def __call__(self, s): | ||
| assert_(type(s) is bytes) | ||
| assert_(type(s) is bytes, | ||
| "write() argument must be a bytes instance, got %s" |
Contributor
Author
There was a problem hiding this comment.
so should I change it to the real errors? Or would we have it backward compatible?
Member
There was a problem hiding this comment.
No I mean, the message could be "__call__ argument must be a bytes instance". Though, as it's a wrapper class, we could leave "write()"
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.
Add descriptive error messages to all assertions in the wsgiref validator middleware that were previously missing them. This makes it much easier to diagnose WSGI compliance issues when using the validation middleware.
The following assertions now include messages: