mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	Issue #27343: Fixed error message for conflicting initializers of ctypes.Structure.
This commit is contained in:
		
						commit
						d91e676fd5
					
				
					 2 changed files with 5 additions and 10 deletions
				
			
		| 
						 | 
					@ -227,10 +227,10 @@ class StructureTestCase(unittest.TestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_conflicting_initializers(self):
 | 
					    def test_conflicting_initializers(self):
 | 
				
			||||||
        class POINT(Structure):
 | 
					        class POINT(Structure):
 | 
				
			||||||
            _fields_ = [("x", c_int), ("y", c_int)]
 | 
					            _fields_ = [("phi", c_float), ("rho", c_float)]
 | 
				
			||||||
        # conflicting positional and keyword args
 | 
					        # conflicting positional and keyword args
 | 
				
			||||||
        self.assertRaises(TypeError, POINT, 2, 3, x=4)
 | 
					        self.assertRaisesRegex(TypeError, "phi", POINT, 2, 3, phi=4)
 | 
				
			||||||
        self.assertRaises(TypeError, POINT, 2, 3, y=4)
 | 
					        self.assertRaisesRegex(TypeError, "rho", POINT, 2, 3, rho=4)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # too many initializers
 | 
					        # too many initializers
 | 
				
			||||||
        self.assertRaises(TypeError, POINT, 2, 3, 4)
 | 
					        self.assertRaises(TypeError, POINT, 2, 3, 4)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4065,14 +4065,9 @@ _init_pos_args(PyObject *self, PyTypeObject *type,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        val = PyTuple_GET_ITEM(args, i + index);
 | 
					        val = PyTuple_GET_ITEM(args, i + index);
 | 
				
			||||||
        if (kwds && PyDict_GetItem(kwds, name)) {
 | 
					        if (kwds && PyDict_GetItem(kwds, name)) {
 | 
				
			||||||
            char *field = PyBytes_AsString(name);
 | 
					 | 
				
			||||||
            if (field == NULL) {
 | 
					 | 
				
			||||||
                PyErr_Clear();
 | 
					 | 
				
			||||||
                field = "???";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            PyErr_Format(PyExc_TypeError,
 | 
					            PyErr_Format(PyExc_TypeError,
 | 
				
			||||||
                         "duplicate values for field '%s'",
 | 
					                         "duplicate values for field %R",
 | 
				
			||||||
                         field);
 | 
					                         name);
 | 
				
			||||||
            Py_DECREF(pair);
 | 
					            Py_DECREF(pair);
 | 
				
			||||||
            Py_DECREF(name);
 | 
					            Py_DECREF(name);
 | 
				
			||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue