summaryrefslogtreecommitdiffstats
path: root/Lib/posixpath.py
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2012-07-15 14:46:23 (GMT)
committerHynek Schlawack <hs@ox.cx>2012-07-15 14:46:23 (GMT)
commit9ac4d8808f21869c558f2d9fd5e46cb083443ea8 (patch)
tree92bb2521ffb02b6d46a3bfb8caaf34d7b134b756 /Lib/posixpath.py
parentb7a5894c64f4ac8353a90e518433cfe025b5b5bc (diff)
parent4774946c3b7564b4a1c93da4ba4dba443a36a708 (diff)
downloadcpython-9ac4d8808f21869c558f2d9fd5e46cb083443ea8.zip
cpython-9ac4d8808f21869c558f2d9fd5e46cb083443ea8.tar.gz
cpython-9ac4d8808f21869c558f2d9fd5e46cb083443ea8.tar.bz2
#15180: Clarify posixpath.join() error message when mixing str & bytes
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r--Lib/posixpath.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 9570a36..ab2aeff 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -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