This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eng793
Recipients eng793
Date 2012-09-02.02:19:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1346552396.88.0.397419581961.issue15845@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2012-09-02 02:19:57eng793setrecipients: + eng793
2012-09-02 02:19:56eng793setmessageid: <1346552396.88.0.397419581961.issue15845@psf.upfronthosting.co.za>
2012-09-02 02:19:56eng793linkissue15845 messages
2012-09-02 02:19:55eng793create