[Python-checkins] [3.11] gh-101936: Update the default value of fp from io.StringIO to io.BytesIO (gh-102100) (gh-102117)
corona10
webhook-mailer at python.org
Wed Feb 22 06:42:34 EST 2023
https://github.com/python/cpython/commit/edbde8feb7496e0f7898a49b80fb703c2d6012a8
commit: edbde8feb7496e0f7898a49b80fb703c2d6012a8
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: corona10 <donghee.na92 at gmail.com>
date: 2023-02-22T20:42:04+09:00
summary:
[3.11] gh-101936: Update the default value of fp from io.StringIO to io.BytesIO (gh-102100) (gh-102117)
gh-101936: Update the default value of fp from io.StringIO to io.BytesIO (gh-102100)
(cherry picked from commit 0d4c7fcd4f078708a5ac6499af378ce5ee8eb211)
Co-authored-by: Long Vo <long.vo at linecorp.com>
files:
A Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst
M Lib/test/test_urllib2.py
M Lib/urllib/error.py
M Misc/ACKS
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index db92ba56c34f..230b937645b5 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1828,6 +1828,7 @@ def test_HTTPError_interface(self):
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 feec0e7f848e..a9cd1ecadd63 100644
--- a/Lib/urllib/error.py
+++ b/Lib/urllib/error.py
@@ -43,7 +43,7 @@ def __init__(self, url, code, msg, hdrs, fp):
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):
diff --git a/Misc/ACKS b/Misc/ACKS
index cf6657f9559a..95e0589076c6 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1882,6 +1882,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 000000000000..55841da44b11
--- /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.
More information about the Python-checkins
mailing list