Skip to content

Commit 4f88406

Browse files
longvhdeveloperpython-sidebar
authored andcommitted
pythongh-101936: Update the default value of fp from io.StringIO to io.BytesIO (pythongh-102100)
Co-authored-by: Long Vo <[email protected]>
1 parent 5ecdace commit 4f88406

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

Lib/test/test_urllib2.py

+1
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,7 @@ def test_HTTPError_interface(self):
18271827
def test_gh_98778(self):
18281828
x = urllib.error.HTTPError("url", 405, "METHOD NOT ALLOWED", None, None)
18291829
self.assertEqual(getattr(x, "__notes__", ()), ())
1830+
self.assertIsInstance(x.fp.read(), bytes)
18301831

18311832
def test_parse_proxy(self):
18321833
parse_proxy_test_cases = [

Lib/urllib/error.py

+1-1
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

+1
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,7 @@ Kurt Vile
18981898
Norman Vine
18991899
Pauli Virtanen
19001900
Frank Visser
1901+
Long Vo
19011902
Johannes Vogel
19021903
Michael Vogt
19031904
Radu Voicilas
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)