mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
#15180: Clarify posixpath.join() error message when mixing str & bytes
This commit is contained in:
commit
9ac4d8808f
3 changed files with 25 additions and 8 deletions
|
@ -74,13 +74,21 @@ def join(a, *p):
|
|||
will be discarded."""
|
||||
sep = _get_sep(a)
|
||||
path = a
|
||||
for b in p:
|
||||
if b.startswith(sep):
|
||||
path = b
|
||||
elif not path or path.endswith(sep):
|
||||
path += b
|
||||
try:
|
||||
for b in p:
|
||||
if b.startswith(sep):
|
||||
path = b
|
||||
elif not path or path.endswith(sep):
|
||||
path += b
|
||||
else:
|
||||
path += sep + b
|
||||
except TypeError:
|
||||
strs = [isinstance(s, str) for s in (a, ) + p]
|
||||
if any(strs) and not all(strs):
|
||||
raise TypeError("Can't mix strings and bytes in path "
|
||||
"components.") from None
|
||||
else:
|
||||
path += sep + b
|
||||
raise
|
||||
return path
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue