diff --git a/Doc/library/urllib.parse.rst b/Doc/library/urllib.parse.rst index ef48addaba03e9..24b2ed47d43485 100644 --- a/Doc/library/urllib.parse.rst +++ b/Doc/library/urllib.parse.rst @@ -220,6 +220,11 @@ or on combining URL components into a URL string. .. versionchanged:: 3.15 Added the *missing_as_none* parameter. + .. versionchanged:: 3.15 + Values for ``url`` and ``scheme`` other than strings, bytes, or ``None`` + raise :exc:`TypeError` if true or :exc:`DeprecationWarning` if false (to + be changed to :exc:`TypeError` in future versions of Python). + .. _WHATWG spec: https://url.spec.whatwg.org/#concept-basic-url-parser @@ -315,6 +320,11 @@ or on combining URL components into a URL string. query parameter separator. This has been changed to allow only a single separator key, with ``&`` as the default separator. + .. versionchanged:: 3.15 + Values for ``qs`` and ``separator`` other than strings, bytes, or + ``None`` raise :exc:`TypeError` if true or :exc:`DeprecationWarning` if + false (to be changed to :exc:`TypeError` in future versions of Python). + .. function:: urlunsplit(parts) urlunsplit(parts, *, keep_empty) @@ -374,6 +384,11 @@ or on combining URL components into a URL string. .. versionchanged:: 3.15 Added the *keep_empty* parameter. + .. versionchanged:: 3.15 + Items in ``parts`` other than strings, bytes, or ``None`` raise + :exc:`TypeError` if true or :exc:`DeprecationWarning` if false (to be + changed to :exc:`TypeError` in future versions of Python). + .. function:: urljoin(base, url, allow_fragments=True) @@ -417,6 +432,11 @@ or on combining URL components into a URL string. Behavior updated to match the semantics defined in :rfc:`3986`. + .. versionchanged:: 3.15 + Values for ``base`` and ``url`` other than strings, bytes, or ``None`` + raise :exc:`TypeError` if true or :exc:`DeprecationWarning` if false (to + be changed to :exc:`TypeError` in future versions of Python). + .. function:: urldefrag(url, *, missing_as_none=False) @@ -447,6 +467,11 @@ or on combining URL components into a URL string. .. versionchanged:: 3.15 Added the *missing_as_none* parameter. + .. versionchanged:: 3.15 + Values other than other than strings, bytes, or ``None`` raise + :exc:`TypeError` if true or :exc:`DeprecationWarning` if false (to be + changed to :exc:`TypeError` in future versions of Python). + .. function:: unwrap(url) Extract the url from a wrapped URL (that is, a string formatted as diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index c4dac339be66af..f67c6220a5d6b6 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1761,6 +1761,13 @@ New deprecations :func:`issubclass`, but warnings were not previously emitted if it was merely imported or accessed from the :mod:`!typing` module. +* :mod:`urllib`: + + * Providing anything but a string, bytes object, or ``None`` to + :mod:`urllib.parse` functions expecting strings or bytes now raises + :exc:`DeprecationWarning` if the value tests false, or :exc:`TypeError` if + it tests true. + (Contributed by Jacob Walls in :issue:`19094`.) * ``__version__`` diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py index 8e4da0e0f09919..ff5cf70ee30470 100644 --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -1255,7 +1255,14 @@ def test_mixed_types_rejected(self): with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urljoin(b"http://python.org", "http://python.org") + def test_non_string_true_values_rejected(self): + # True values raise informative TypeErrors + msg = "Expected a string, bytes, or None: got