Skip to content

Commit 9107190

Browse files
authored
Merge pull request #389 from python/master
bpo-42967: Fix urllib.parse docs and make logic clearer (pythonGH-24536)
2 parents 2d45cff + a2f0654 commit 9107190

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

Doc/library/urllib.parse.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ or on combining URL components into a URL string.
190190
read. If set, then throws a :exc:`ValueError` if there are more than
191191
*max_num_fields* fields read.
192192

193-
The optional argument *separator* is the symbol to use for separating the query arguments. It defaults to `&`.
193+
The optional argument *separator* is the symbol to use for separating the
194+
query arguments. It defaults to ``&``.
194195

195196
Use the :func:`urllib.parse.urlencode` function (with the ``doseq``
196197
parameter set to ``True``) to convert such dictionaries into query
@@ -204,8 +205,10 @@ or on combining URL components into a URL string.
204205
Added *max_num_fields* parameter.
205206

206207
.. versionchanged:: 3.10
207-
Added *separator* parameter with the default value of `&`. Python versions earlier than Python 3.10 allowed using both ";" and "&" as
208-
query parameter separator. This has been changed to allow only a single separator key, with "&" as the default separator.
208+
Added *separator* parameter with the default value of ``&``. Python
209+
versions earlier than Python 3.10 allowed using both ``;`` and ``&`` as
210+
query parameter separator. This has been changed to allow only a single
211+
separator key, with ``&`` as the default separator.
209212

210213

211214
.. function:: parse_qsl(qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace', max_num_fields=None, separator='&')
@@ -232,7 +235,8 @@ or on combining URL components into a URL string.
232235
read. If set, then throws a :exc:`ValueError` if there are more than
233236
*max_num_fields* fields read.
234237

235-
The optional argument *separator* is the symbol to use for separating the query arguments. It defaults to `&`.
238+
The optional argument *separator* is the symbol to use for separating the
239+
query arguments. It defaults to ``&``.
236240

237241
Use the :func:`urllib.parse.urlencode` function to convert such lists of pairs into
238242
query strings.
@@ -244,8 +248,10 @@ or on combining URL components into a URL string.
244248
Added *max_num_fields* parameter.
245249

246250
.. versionchanged:: 3.10
247-
Added *separator* parameter with the default value of `&`. Python versions earlier than Python 3.10 allowed using both ";" and "&" as
248-
query parameter separator. This has been changed to allow only a single separator key, with "&" as the default separator.
251+
Added *separator* parameter with the default value of ``&``. Python
252+
versions earlier than Python 3.10 allowed using both ``;`` and ``&`` as
253+
query parameter separator. This has been changed to allow only a single
254+
separator key, with ``&`` as the default separator.
249255

250256

251257
.. function:: urlunparse(parts)

Doc/whatsnew/3.6.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,11 +2447,11 @@ details, see the documentation for ``loop.create_datagram_endpoint()``.
24472447
Notable changes in Python 3.6.13
24482448
================================
24492449

2450-
Earlier Python versions allowed using both ";" and "&" as
2450+
Earlier Python versions allowed using both ``;`` and ``&`` as
24512451
query parameter separators in :func:`urllib.parse.parse_qs` and
24522452
:func:`urllib.parse.parse_qsl`. Due to security concerns, and to conform with
24532453
newer W3C recommendations, this has been changed to allow only a single
2454-
separator key, with "&" as the default. This change also affects
2454+
separator key, with ``&`` as the default. This change also affects
24552455
:func:`cgi.parse` and :func:`cgi.parse_multipart` as they use the affected
24562456
functions internally. For more details, please see their respective
24572457
documentation.

Doc/whatsnew/3.8.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,11 +2238,11 @@ details, see the documentation for ``loop.create_datagram_endpoint()``.
22382238
Notable changes in Python 3.8.8
22392239
===============================
22402240

2241-
Earlier Python versions allowed using both ";" and "&" as
2241+
Earlier Python versions allowed using both ``;`` and ``&`` as
22422242
query parameter separators in :func:`urllib.parse.parse_qs` and
22432243
:func:`urllib.parse.parse_qsl`. Due to security concerns, and to conform with
22442244
newer W3C recommendations, this has been changed to allow only a single
2245-
separator key, with "&" as the default. This change also affects
2245+
separator key, with ``&`` as the default. This change also affects
22462246
:func:`cgi.parse` and :func:`cgi.parse_multipart` as they use the affected
22472247
functions internally. For more details, please see their respective
22482248
documentation.

Doc/whatsnew/3.9.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,11 +1520,11 @@ become a :exc:`TypeError` in Python 3.10.
15201520
urllib.parse
15211521
------------
15221522

1523-
Earlier Python versions allowed using both ";" and "&" as
1523+
Earlier Python versions allowed using both ``;`` and ``&`` as
15241524
query parameter separators in :func:`urllib.parse.parse_qs` and
15251525
:func:`urllib.parse.parse_qsl`. Due to security concerns, and to conform with
15261526
newer W3C recommendations, this has been changed to allow only a single
1527-
separator key, with "&" as the default. This change also affects
1527+
separator key, with ``&`` as the default. This change also affects
15281528
:func:`cgi.parse` and :func:`cgi.parse_multipart` as they use the affected
15291529
functions internally. For more details, please see their respective
15301530
documentation.

Lib/urllib/parse.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,7 @@ def parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
734734
"""
735735
qs, _coerce_result = _coerce_args(qs)
736736

737-
if not separator or (not isinstance(separator, str)
738-
and not isinstance(separator, bytes)):
737+
if not separator or (not isinstance(separator, (str, bytes))):
739738
raise ValueError("Separator must be of type string or bytes.")
740739

741740
# If max_num_fields is defined then check that the number of fields

0 commit comments

Comments
 (0)