Skip to content

Commit edbde8f

Browse files
[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 0d4c7fc) Co-authored-by: Long Vo <[email protected]>
1 parent 528e91c commit edbde8f

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

Lib/test/test_urllib2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,7 @@ def test_HTTPError_interface(self):
18281828
def test_gh_98778(self):
18291829
x = urllib.error.HTTPError("url", 405, "METHOD NOT ALLOWED", None, None)
18301830
self.assertEqual(getattr(x, "__notes__", ()), ())
1831+
self.assertIsInstance(x.fp.read(), bytes)
18311832

18321833
def test_parse_proxy(self):
18331834
parse_proxy_test_cases = [

Lib/urllib/error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, url, code, msg, hdrs, fp):
4343
self.fp = fp
4444
self.filename = url
4545
if fp is None:
46-
fp = io.StringIO()
46+
fp = io.BytesIO()
4747
self.__super_init(fp, hdrs, url, code)
4848

4949
def __str__(self):

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,7 @@ Kurt Vile
18821882
Norman Vine
18831883
Pauli Virtanen
18841884
Frank Visser
1885+
Long Vo
18851886
Johannes Vogel
18861887
Michael Vogt
18871888
Radu Voicilas
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The default value of ``fp`` becomes :class:`io.BytesIO` if :exc:`~urllib.error.HTTPError`
2+
is initialized without a designated ``fp`` parameter. Patch by Long Vo.

0 commit comments

Comments
 (0)