python / python/cpython

Allow derived classes for str and tuple in WSGI validator

Open
#93,637 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

The WSGI validator could allow anything that inherits from tuple[str, str] for the headers, instead of literally just tuple[str, str] and nothing else.

Pitch

This is so I can use classes that extend str and tuple[str, str] as headers.
Symbolic types that add essentially nothing but a pretty constructor and type checks avoid silly mistakes by encoding intent.

Previous discussion

On IRC I was told about contravariance. https://peps.python.org/pep-0484/#covariance-and-contravariance
I think it might be fine, because no matter which class extending its type I will feed it, it's never coming back, so there is no risk of an item of a less precise type bubbling up to the caller somehow.

Linked PRs
  • gh-93640

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the WSGI validator entry point and inspect linked PR gh-93640 before beginning, since the issue indicates related work elsewhere. Confirm whether the validator accepts subclasses of str and tuple[str, str] while preserving its current rejection behavior; done means the intended derived header classes are accepted and the existing validator behavior remains covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.