[Python-checkins] cpython (3.5): Issue #27343: Fixed error message for conflicting initializers of
serhiy.storchaka
python-checkins at python.org
Sat Jun 18 02:59:16 EDT 2016
https://hg.python.org/cpython/rev/ed81fc7e285b
changeset: 102081:ed81fc7e285b
branch: 3.5
parent: 102073:15900c612ca7
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sat Jun 18 09:58:24 2016 +0300
summary:
Issue #27343: Fixed error message for conflicting initializers of ctypes.Structure.
files:
Lib/ctypes/test/test_structures.py | 6 +++---
Modules/_ctypes/_ctypes.c | 9 ++-------
2 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py
--- a/Lib/ctypes/test/test_structures.py
+++ b/Lib/ctypes/test/test_structures.py
@@ -227,10 +227,10 @@
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)
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -4065,14 +4065,9 @@
}
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;
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list