Skip to content

gh-58857: Add error messages to bare assertions in wsgiref.validate#148291

Open
gaweng wants to merge 1 commit intopython:mainfrom
gaweng:fix-wsgiref-validator-messages
Open

gh-58857: Add error messages to bare assertions in wsgiref.validate#148291
gaweng wants to merge 1 commit intopython:mainfrom
gaweng:fix-wsgiref-validator-messages

Conversation

@gaweng
Copy link
Copy Markdown
Contributor

@gaweng gaweng commented Apr 9, 2026

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

…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
Copy link
Copy Markdown
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, this is __call__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants