[issue15845] Fixing some byte-to-string conversion warnings
Alessandro Moura
report at bugs.python.org
Sun Sep 2 04:19:57 CEST 2012
New submission from Alessandro Moura:
This is related to issue 15826.
When run with the -b option, some glob.py and os.py functions give warnings due to byte-to-string conversions:
amoura at amoura-laptop:~/cpython$ ./python -b -c "import glob; glob.glob(b'cover*/glob.cover')"
/home/amoura/cpython/Lib/glob.py:64: BytesWarning: Comparison between bytes and string
if basename == '':
amoura at amoura-laptop:~/cpython$ ./python -b -c "import os; os.makedirs(b'tst/making/dirs')"
/home/amoura/cpython/Lib/os.py:266: BytesWarning: Comparison between bytes and string
if tail == cdir: # xxx/newdir/. exists if xxx/newdir exists
The attached patch fixes this.
There is a rather more mysterious phenomenon with exceptions (which is triggered by test_exceptions for ImportException, but it happens for any Exception class):
>>> e = Exception(b'aaa')
[60596 refs]
>>> e.args[0]
b'aaa'
[60601 refs]
>>> str(e)
__main__:1: BytesWarning: str() on a bytes instance
"b'aaa'"
[60615 refs]
>>> e.args[0]
b'aaa'
[60615 refs]
>>> str(e)
"b'aaa'"
[60615 refs]
>>> e.args[0]
b'aaa'
[60615 refs]
In other words, if a bytes argument is given to the exception, the first call to str triggers the warning, but further calls don't. Is this worth pursuing?
----------
components: Library (Lib)
files: os_glob_bytes.patch
keywords: patch
messages: 169683
nosy: eng793
priority: normal
severity: normal
status: open
title: Fixing some byte-to-string conversion warnings
type: enhancement
versions: Python 3.3
Added file: http://bugs.python.org/file27092/os_glob_bytes.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15845>
_______________________________________
More information about the Python-bugs-list
mailing list