[New-bugs-announce] [issue15180] Cryptic traceback from os.path.join when mixing str & bytes
Nick Coghlan
report at bugs.python.org
Mon Jun 25 13:45:37 CEST 2012
New submission from Nick Coghlan <ncoghlan at gmail.com>:
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.python.org>
<http://bugs.python.org/issue15180>
_______________________________________
More information about the New-bugs-announce
mailing list