
report at bugs
Jun 25, 2012, 4:45 AM
Post #1 of 15
(233 views)
Permalink
|
|
[issue15180] Cryptic traceback from os.path.join when mixing str & bytes
|
|
New submission from Nick Coghlan <ncoghlan [at] gmail>: As seen in #4489, the traceback when mixing str and bytes in os.path.join is rather cryptic and hard to decipher if you've never encountered it before: >>> import os.path >>> os.path.join(b'', '') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python3.2/posixpath.py", line 78, in join if b.startswith(sep): TypeError: startswith first arg must be str or a tuple of str, not bytes >>> os.path.join('', b'') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python3.2/posixpath.py", line 78, in join if b.startswith(sep): TypeError: startswith first arg must be bytes or a tuple of bytes, not str While it's slightly less cryptic with a real source file (since you can at least see the os.path.join call), you have to have some how idea of how os.path.join works to realise that: - type(sep) == type(args[0]) - b in args[1:] The challenge is to generate a more user friendly error message without making the normal case of correct types any slower. ---------- components: Library (Lib) messages: 163945 nosy: ncoghlan priority: normal severity: normal stage: needs patch status: open title: Cryptic traceback from os.path.join when mixing str & bytes type: enhancement versions: Python 3.3 _______________________________________ Python tracker <report [at] bugs> <http://bugs.python.org/issue15180> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
|