diff options
| author | Vo Hoang Long <vohoanglong07@gmail.com> | 2023-02-21 22:14:41 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-22 00:14:41 +0900 |
| commit | 0d4c7fcd4f078708a5ac6499af378ce5ee8eb211 (patch) | |
| tree | 8eee1990e04156e58947481ceaf556f8f646b8b0 | |
| parent | c2b85a95a50687a2e5d1873e17266370876e77e9 (diff) | |
| download | cpython-git-0d4c7fcd4f078708a5ac6499af378ce5ee8eb211.tar.gz | |
gh-101936: Update the default value of fp from io.StringIO to io.BytesIO (gh-102100)
Co-authored-by: Long Vo <long.vo@linecorp.com>
| -rw-r--r-- | Lib/test/test_urllib2.py | 1 | ||||
| -rw-r--r-- | Lib/urllib/error.py | 2 | ||||
| -rw-r--r-- | Misc/ACKS | 1 | ||||
| -rw-r--r-- | Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst | 2 |
4 files changed, 5 insertions, 1 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 498c0382d2..633d596ac3 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1827,6 +1827,7 @@ class MiscTests(unittest.TestCase): def test_gh_98778(self): x = urllib.error.HTTPError("url", 405, "METHOD NOT ALLOWED", None, None) self.assertEqual(getattr(x, "__notes__", ()), ()) + self.assertIsInstance(x.fp.read(), bytes) def test_parse_proxy(self): parse_proxy_test_cases = [ diff --git a/Lib/urllib/error.py b/Lib/urllib/error.py index feec0e7f84..a9cd1ecadd 100644 --- a/Lib/urllib/error.py +++ b/Lib/urllib/error.py @@ -43,7 +43,7 @@ class HTTPError(URLError, urllib.response.addinfourl): self.fp = fp self.filename = url if fp is None: - fp = io.StringIO() + fp = io.BytesIO() self.__super_init(fp, hdrs, url, code) def __str__(self): @@ -1898,6 +1898,7 @@ Kurt Vile Norman Vine Pauli Virtanen Frank Visser +Long Vo Johannes Vogel Michael Vogt Radu Voicilas diff --git a/Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst b/Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst new file mode 100644 index 0000000000..55841da44b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst @@ -0,0 +1,2 @@ +The default value of ``fp`` becomes :class:`io.BytesIO` if :exc:`~urllib.error.HTTPError` +is initialized without a designated ``fp`` parameter. Patch by Long Vo. |
