diff -r d943089af1c6 Lib/posixpath.py --- a/Lib/posixpath.py Mon Jun 30 04:04:52 2014 +0300 +++ b/Lib/posixpath.py Sun Jun 29 23:10:30 2014 -0400 @@ -34,6 +34,7 @@ defpath = ':/bin:/usr/bin' altsep = None devnull = '/dev/null' +mixed_string_binary_error = "Can't mix strings and bytes in path components." def _get_sep(path): if isinstance(path, bytes): @@ -87,8 +88,7 @@ for s in (a, ) + p) if valid_types: # Must have a mixture of text and binary data - raise TypeError("Can't mix strings and bytes in path " - "components.") from None + raise TypeError(mixed_string_binary_error) from None raise return path @@ -447,9 +447,15 @@ 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] - + 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] + except TypeError as e: + valid_types = all(isinstance(s, (str, bytes, bytearray)) + for s in [start, path]) + if valid_types: + raise TypeError(mixed_string_binary_error) from None + raise # Work out how much of the filepath is shared by start and path. i = len(commonprefix([start_list, path_list]))