diff options
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r-- | Lib/posixpath.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 0aa53fe..44ed838 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -82,11 +82,8 @@ def join(a, *p): path += b else: path += sep + b - except TypeError: - if all(isinstance(s, (str, bytes)) for s in (a,) + p): - # Must have a mixture of text and binary data - raise TypeError("Can't mix strings and bytes in path " - "components") from None + except (TypeError, AttributeError, BytesWarning): + genericpath._check_arg_types('join', a, *p) raise return path @@ -445,13 +442,16 @@ def relpath(path, start=None): if start is None: start = curdir - start_list = [x for x in abspath(start).split(sep) if x] - path_list = [x for x in abspath(path).split(sep) if x] - - # Work out how much of the filepath is shared by start and path. - i = len(commonprefix([start_list, path_list])) - - rel_list = [pardir] * (len(start_list)-i) + path_list[i:] - if not rel_list: - return curdir - return join(*rel_list) + try: + start_list = [x for x in abspath(start).split(sep) if x] + path_list = [x for x in abspath(path).split(sep) if x] + # Work out how much of the filepath is shared by start and path. + i = len(commonprefix([start_list, path_list])) + + rel_list = [pardir] * (len(start_list)-i) + path_list[i:] + if not rel_list: + return curdir + return join(*rel_list) + except (TypeError, AttributeError, BytesWarning, DeprecationWarning): + genericpath._check_arg_types('relpath', path, start) + raise |