diff options
author | Hynek Schlawack <hs@ox.cx> | 2012-07-15 14:21:30 (GMT) |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2012-07-15 14:21:30 (GMT) |
commit | 4774946c3b7564b4a1c93da4ba4dba443a36a708 (patch) | |
tree | 2c668f86fdb8f658f7eb73bf04f46139d92fb627 /Lib/posixpath.py | |
parent | a3d1cac4b21ffbd8deed0c28f08bed4afa5e7b83 (diff) | |
download | cpython-4774946c3b7564b4a1c93da4ba4dba443a36a708.zip cpython-4774946c3b7564b4a1c93da4ba4dba443a36a708.tar.gz cpython-4774946c3b7564b4a1c93da4ba4dba443a36a708.tar.bz2 |
#15180: Clarify posixpath.join() error message when mixing str & bytes
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r-- | Lib/posixpath.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 9570a36..84bcc13 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -74,13 +74,20 @@ 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.") else: - path += sep + b + raise return path |