Issue11681
Created on 2011-03-26 00:53 by eric.araujo, last changed 2012-06-26 18:26 by moijes12.
| Messages (8) | |||
|---|---|---|---|
| msg132195 - (view) | Author: Éric Araujo (eric.araujo) * ![]() |
Date: 2011-03-26 00:53 | |
Python 2 has a -b command-line option which is undocumented. It is used by the warnings machinery to decide to warn about (-b) or raise an error (-bb) if someone uses str(bytes) or str(buffer) (explanation courtesy of grep and Python/pythonrun.c). |
|||
| msg132197 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2011-03-26 01:05 | |
Are you sure? (see issue 10471). I don't see how -b could do anything in python2, since bytes and string are the same there (and, indeed, from command line experimentation it doesn't seem to). |
|||
| msg132198 - (view) | Author: Éric Araujo (eric.araujo) * ![]() |
Date: 2011-03-26 01:08 | |
The code definitely is in 2.7. Python/_warnings.c:861: if (Py_BytesWarningFlag > 1) Python/_warnings.c:863: else if (Py_BytesWarningFlag) Python/_warnings.c:867: PyList_SET_ITEM(filters, pos++, create_filter(PyExc_BytesWarning, Python/sysmodule.c:1257: SetFlag(Py_BytesWarningFlag); Python/pythonrun.c:81:int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */ Include/pydebug.h:14:PyAPI_DATA(int) Py_BytesWarningFlag; Include/pyerrors.h:178:PyAPI_DATA(PyObject *) PyExc_BytesWarning; Modules/main.c:285: Py_BytesWarningFlag++; Objects/bytearrayobject.c:1003: if (Py_BytesWarningFlag) { Objects/bytearrayobject.c:1004: if (PyErr_WarnEx(PyExc_BytesWarning, Objects/bytearrayobject.c:1028: if (Py_BytesWarningFlag && op == Py_EQ) { Objects/bytearrayobject.c:1029: if (PyErr_WarnEx(PyExc_BytesWarning, Objects/exceptions.c:2018: * BytesWarning extends Warning Objects/exceptions.c:2020:SimpleExtendsException(PyExc_Warning, BytesWarning, Objects/exceptions.c:2110: PRE_INIT(BytesWarning) Objects/exceptions.c:2178: POST_INIT(BytesWarning) Lib/warnings.py:399: simplefilter(bytes_action, category=BytesWarning, append=1) Lib/test/test_bytes.py:25: with test.test_support.check_warnings(('', BytesWarning)): Lib/test/exception_hierarchy.txt:50: +-- BytesWarning Include/pydebug.h:14:PyAPI_DATA(int) Py_BytesWarningFlag; Include/pyerrors.h:178:PyAPI_DATA(PyObject *) PyExc_BytesWarning; Doc/library/warnings.rst:164:* :exc:`BytesWarning` is ignored unless the :option:`-b` option is given once or |
|||
| msg132200 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2011-03-26 01:12 | |
rdmurray@hey:~/python/p27>cat temp.py x = bytes('abc') print x print str(x) rdmurray@hey:~/python/p27>./python -bb temp.py abc abc |
|||
| msg132201 - (view) | Author: Éric Araujo (eric.araujo) * ![]() |
Date: 2011-03-26 01:17 | |
test_bytes has a branch for -b and passes without it, with -b and with -bb. I really don’t know. |
|||
| msg132300 - (view) | Author: Nick Coghlan (ncoghlan) * ![]() |
Date: 2011-03-27 09:57 | |
Even "from __future__ import unicode_literals" doesn't make it do anything. Perhaps Christian merged it by mistake in [5341b30b1812]? |
|||
| msg132354 - (view) | Author: Marc-Andre Lemburg (lemburg) * ![]() |
Date: 2011-03-27 18:34 | |
Nick Coghlan wrote: > > Nick Coghlan <ncoghlan@gmail.com> added the comment: > > Even "from __future__ import unicode_literals" doesn't make it do anything. > > Perhaps Christian merged it by mistake in [5341b30b1812]? It looks more like some parts were left out in the merge by accident: The 2.7 code only raises the warning for bytearrays, not for bytes and buffers, whereas 3.2 issues the warning for all bytes and bytearray (but not buffers; which makes sense, since Python 3 no longer has a text buffer interface). |
|||
| msg164089 - (view) | Author: moijes12 (moijes12) | Date: 2012-06-26 18:26 | |
Hi Marc I tried reproducing this for bytearray using Python 2.7.2 but I can't see a warning. devel@moses:~$ python --version Python 2.7.2+ devel@moses:~$ cat test_py.py k = range(10) kb = bytearray(k) print kb kb = bytearray("hi") print kb devel@moses:~$ python -b test_py.py hi devel@moses:~$ python -bb test_py.py hi Please correct me if I'm wrong anywhere here. I'd like to work on this. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2012-06-26 18:26:22 | moijes12 | set | nosy:
+ moijes12 messages: + msg164089 |
| 2011-03-27 18:34:09 | lemburg | set | nosy:
+ lemburg messages: + msg132354 |
| 2011-03-27 09:57:29 | ncoghlan | set | nosy:
+ ncoghlan messages: + msg132300 |
| 2011-03-26 19:08:02 | ezio.melotti | set | nosy:
+ ezio.melotti |
| 2011-03-26 01:17:56 | eric.araujo | set | messages: + msg132201 |
| 2011-03-26 01:12:00 | r.david.murray | set | messages: + msg132200 |
| 2011-03-26 01:08:34 | eric.araujo | set | nosy:
+ georg.brandl messages: + msg132198 |
| 2011-03-26 01:05:40 | r.david.murray | set | nosy:
+ r.david.murray messages: + msg132197 |
| 2011-03-26 00:53:45 | eric.araujo | create | |
