]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-30134: fix BytesWarning doc, docstring and message (GH-12739)
authorInada Naoki <songofacandy@gmail.com>
Tue, 9 Apr 2019 12:49:49 +0000 (21:49 +0900)
committerGitHub <noreply@github.com>
Tue, 9 Apr 2019 12:49:49 +0000 (21:49 +0900)
Doc/library/exceptions.rst
Doc/library/warnings.rst
Include/code.h
Objects/bytearrayobject.c
Objects/exceptions.c
Python/pythonrun.c

index 2bc2bce00adc176461327d92663da886cb02110d..3cb944555bd974c27e684eabba278543e6b82240 100644 (file)
@@ -526,7 +526,7 @@ module for more information.
 
 .. 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
 
index b5b89c97c560e6ed07c1e3bbe73a8c77ec22e4e6..2f699ea8f55138c56cf4cb5dae7641c511893ab3 100644 (file)
@@ -92,7 +92,7 @@ following warnings category classes are currently defined:
 |                                  | 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,
index 7456fd610f980789161c4507d0f9884a0c03f3d8..26c571ae8727b172e9829e78ac4012baeeb9c0cf 100644 (file)
@@ -104,7 +104,7 @@ PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co,
  *
  * 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,
index a96d6d981ddd2c3995739cc54cf3940a2b674e39..582483247769059d9cc119a9df0e2fcf2883266b 100644 (file)
@@ -1027,14 +1027,6 @@ bytearray_repr(PyByteArrayObject *self)
 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));
 }
 
@@ -1059,7 +1051,7 @@ bytearray_richcompare(PyObject *self, PyObject *other, int 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;
         }
 
index 224d1ba08afb5ca9b5ce6c5f03c6c16ba31cd72a..fc601521208155c4cfcd10f2a44643e1f942b597 100644 (file)
@@ -2014,8 +2014,8 @@ SimpleExtendsException(PyExc_Warning, UnicodeWarning,
  *    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!
index 2c9f55fbd1dff32059f2443ed33d259d41956f14..abdfb146ae51f16f9172028f4168f84505066e1f 100644 (file)
@@ -70,7 +70,7 @@ int Py_VerboseFlag; /* Needed by import.c */
 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 */