.. exception:: BytesWarning
- Base class for warnings related to :class:`str` and :class:`bytearray`.
+ Base class for warnings related to bytes and bytearray.
.. versionadded:: 2.6
| | Unicode. |
+----------------------------------+-----------------------------------------------+
| :exc:`BytesWarning` | Base category for warnings related to |
-| | str and bytearray. |
+| | bytes and bytearray. |
+----------------------------------+-----------------------------------------------+
While these are technically built-in exceptions, they are documented here,
*
* Return (type(obj), obj, ...): a tuple with variable size (at least 2 items)
* depending on the type and the value. The type is the first item to not
- * compare bytes and str which can raise a BytesWarning exception. */
+ * compare bytes and unicode which can raise a BytesWarning exception. */
PyAPI_FUNC(PyObject*) _PyCode_ConstantKey(PyObject *obj);
PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
static PyObject *
bytearray_str(PyObject *op)
{
-#if 0
- if (Py_BytesWarningFlag) {
- if (PyErr_WarnEx(PyExc_BytesWarning,
- "str() on a bytearray instance", 1))
- return NULL;
- }
- return bytearray_repr((PyByteArrayObject*)op);
-#endif
return PyBytes_FromStringAndSize(((PyByteArrayObject*)op)->ob_bytes, Py_SIZE(op));
}
if (rc) {
if (Py_BytesWarningFlag && op == Py_EQ) {
if (PyErr_WarnEx(PyExc_BytesWarning,
- "Comparison between bytearray and string", 1))
+ "Comparison between bytearray and unicode", 1))
return NULL;
}
* BytesWarning extends Warning
*/
SimpleExtendsException(PyExc_Warning, BytesWarning,
- "Base class for warnings about bytes and buffer related problems, mostly\n"
- "related to conversion from str or comparing to str.");
+ "Base class for warnings about bytes and bytearray related problems, \n"
+ "mostly related to comparing to str.");
/* Pre-computed MemoryError instance. Best to create this as early as
* possible and not wait until a MemoryError is actually raised!
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
int Py_InspectFlag; /* Needed to determine whether to exit at SystemExit */
int Py_NoSiteFlag; /* Suppress 'import site' */
-int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */
+int Py_BytesWarningFlag; /* Warn on comparison between bytearray and unicode */
int Py_DontWriteBytecodeFlag; /* Suppress writing bytecode files (*.py[co]) */
int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
int Py_FrozenFlag; /* Needed by getpath.c */