Simplify and fix urllib.parse.urlencode() (#13815)

Remove overloads and type vars. Introduce a protocol for the
`quote_via` argument. This means that the interface accepted by the
supplied `quote_via` is stricter, and is not dependent on the actual
supplied types in the `query` argument, but must work with all
possible query types.
This commit is contained in:
Sebastian Rittau
2025-04-14 11:11:06 +02:00
committed by GitHub
parent 3941e06bfc
commit de317e1c74
2 changed files with 32 additions and 26 deletions
@@ -0,0 +1,12 @@
from __future__ import annotations
from urllib.parse import quote, quote_plus, urlencode
urlencode({"a": "b"}, quote_via=quote)
urlencode({b"a": b"b"}, quote_via=quote)
urlencode({"a": b"b"}, quote_via=quote)
urlencode({b"a": "b"}, quote_via=quote)
mixed_dict: dict[str | bytes, str | bytes] = {}
urlencode(mixed_dict, quote_via=quote)
urlencode({"a": "b"}, quote_via=quote_plus)