Skip to content

Commit cbc95c6

Browse files
Improve error message wording
1 parent 0d5f50b commit cbc95c6

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

Lib/test/test_urlparse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -850,27 +850,27 @@ def test_mixed_types_rejected(self):
850850
def test_forbidden_types(self):
851851
with self.assertRaisesRegex(
852852
TypeError,
853-
"Expected string or bytes: got <class 'list'>"):
853+
"Expected a string or bytes object: got <class 'list'>"):
854854
urllib.parse.urljoin('http://www.python.org', [])
855855
with self.assertRaisesRegex(
856856
TypeError,
857-
"Expected string or bytes: got <class 'list'>"):
857+
"Expected a string or bytes object: got <class 'list'>"):
858858
urllib.parse.urljoin([], b'docs')
859859
with self.assertRaisesRegex(
860860
TypeError,
861-
"Expected string or bytes: got <class 'NoneType'>"):
861+
"Expected a string or bytes object: got <class 'NoneType'>"):
862862
urllib.parse.urlparse(b'www.python.org', None)
863863
with self.assertRaisesRegex(
864864
TypeError,
865-
"Expected string or bytes: got <class 'dict'>"):
865+
"Expected a string or bytes object: got <class 'dict'>"):
866866
urllib.parse.urlparse({}, '')
867867
with self.assertRaisesRegex(
868868
TypeError,
869-
"Expected string or bytes: got <class 'int'>"):
869+
"Expected a string or bytes object: got <class 'int'>"):
870870
urllib.parse.urlsplit(0, 'http')
871871
with self.assertRaisesRegex(
872872
TypeError,
873-
"Expected string or bytes: got <class 'NoneType'>"):
873+
"Expected a string or bytes object: got <class 'NoneType'>"):
874874
urllib.parse.urlsplit('http://www.python.org', None)
875875

876876
def _check_result_type(self, str_type):

Lib/urllib/parse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,9 @@ def urlparse(url, scheme='', allow_fragments=True):
384384
Note that % escapes are not expanded.
385385
"""
386386
if not isinstance(url, (str, bytes, bytearray)):
387-
raise TypeError(f'Expected string or bytes: got {type(url)}')
387+
raise TypeError(f'Expected a string or bytes object: got {type(url)}')
388388
if not isinstance(scheme, (str, bytes, bytearray)):
389-
raise TypeError(f'Expected string or bytes: got {type(scheme)}')
389+
raise TypeError(f'Expected a string or bytes object: got {type(scheme)}')
390390
url, scheme, _coerce_result = _coerce_args(url, scheme)
391391
splitresult = urlsplit(url, scheme, allow_fragments)
392392
scheme, netloc, url, query, fragment = splitresult
@@ -456,9 +456,9 @@ def urlsplit(url, scheme='', allow_fragments=True):
456456
Note that % escapes are not expanded.
457457
"""
458458
if not isinstance(url, (str, bytes, bytearray)):
459-
raise TypeError(f'Expected string or bytes: got {type(url)}')
459+
raise TypeError(f'Expected a string or bytes object: got {type(url)}')
460460
if not isinstance(scheme, (str, bytes, bytearray)):
461-
raise TypeError(f'Expected string or bytes: got {type(scheme)}')
461+
raise TypeError(f'Expected a string or bytes object: got {type(scheme)}')
462462

463463
url, scheme, _coerce_result = _coerce_args(url, scheme)
464464

@@ -523,9 +523,9 @@ def urljoin(base, url, allow_fragments=True):
523523
"""Join a base URL and a possibly relative URL to form an absolute
524524
interpretation of the latter."""
525525
if not isinstance(base, (str, bytes, bytearray)):
526-
raise TypeError(f'Expected string or bytes: got {type(base)}')
526+
raise TypeError(f'Expected a string or bytes object: got {type(base)}')
527527
if not isinstance(url, (str, bytes, bytearray)):
528-
raise TypeError(f'Expected string or bytes: got {type(url)}')
528+
raise TypeError(f'Expected a string or bytes object: got {type(url)}')
529529

530530
if not base:
531531
return url

0 commit comments

Comments
 (0)