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@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?

----------
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 <rep...@bugs.python.org>
<http://bugs.python.org/issue15845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to