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>
This commit is contained in:
Vo Hoang Long 2023-02-21 22:14:41 +07:00 committed by GitHub
parent c2b85a95a5
commit 0d4c7fcd4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 1 deletions

View File

@ -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 = [

View File

@ -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):

View File

@ -1898,6 +1898,7 @@ Kurt Vile
Norman Vine
Pauli Virtanen
Frank Visser
Long Vo
Johannes Vogel
Michael Vogt
Radu Voicilas

View File

@ -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.