Message169683
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@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@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? |
|
Date |
User |
Action |
Args |
2012-09-02 02:19:57 | eng793 | set | recipients:
+ eng793 |
2012-09-02 02:19:56 | eng793 | set | messageid: <1346552396.88.0.397419581961.issue15845@psf.upfronthosting.co.za> |
2012-09-02 02:19:56 | eng793 | link | issue15845 messages |
2012-09-02 02:19:55 | eng793 | create | |
|