]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #27343: Fixed error message for conflicting initializers of ctypes.Structure.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 18 Jun 2016 06:58:24 +0000 (09:58 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 18 Jun 2016 06:58:24 +0000 (09:58 +0300)
Lib/ctypes/test/test_structures.py
Modules/_ctypes/_ctypes.c

index 84d456c3cc383536d55c1c87102f959767f030f1..d998c274888a1bafce0f1a722d1c4f14a5df7980 100644 (file)
@@ -227,10 +227,10 @@ class StructureTestCase(unittest.TestCase):
 
     def test_conflicting_initializers(self):
         class POINT(Structure):
-            _fields_ = [("x", c_int), ("y", c_int)]
+            _fields_ = [("phi", c_float), ("rho", c_float)]
         # conflicting positional and keyword args
-        self.assertRaises(TypeError, POINT, 2, 3, x=4)
-        self.assertRaises(TypeError, POINT, 2, 3, y=4)
+        self.assertRaisesRegex(TypeError, "phi", POINT, 2, 3, phi=4)
+        self.assertRaisesRegex(TypeError, "rho", POINT, 2, 3, rho=4)
 
         # too many initializers
         self.assertRaises(TypeError, POINT, 2, 3, 4)
index 311fb5d64595d165b25d948532e0069d548a75ba..a7a81056bc9d3ac378ff17126f21de5d6d2e0051 100644 (file)
@@ -4065,14 +4065,9 @@ _init_pos_args(PyObject *self, PyTypeObject *type,
         }
         val = PyTuple_GET_ITEM(args, i + index);
         if (kwds && PyDict_GetItem(kwds, name)) {
-            char *field = PyBytes_AsString(name);
-            if (field == NULL) {
-                PyErr_Clear();
-                field = "???";
-            }
             PyErr_Format(PyExc_TypeError,
-                         "duplicate values for field '%s'",
-                         field);
+                         "duplicate values for field %R",
+                         name);
             Py_DECREF(pair);
             Py_DECREF(name);
             return -1;