mirror of https://github.com/python/cpython
Raise a TypeError instead of a ValueError when too many initializers
are used in a Structure or Union constructor.
This commit is contained in:
parent
02ec289f3e
commit
415c1e36a9
|
@ -222,8 +222,8 @@ class StructureTestCase(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, POINT, 2, 3, x=4)
|
self.assertRaises(TypeError, POINT, 2, 3, x=4)
|
||||||
self.assertRaises(TypeError, POINT, 2, 3, y=4)
|
self.assertRaises(TypeError, POINT, 2, 3, y=4)
|
||||||
|
|
||||||
# Should this raise TypeError instead?
|
# too many initializers
|
||||||
self.assertRaises(ValueError, POINT, 2, 3, 4)
|
self.assertRaises(TypeError, POINT, 2, 3, 4)
|
||||||
|
|
||||||
def test_keyword_initializers(self):
|
def test_keyword_initializers(self):
|
||||||
class POINT(Structure):
|
class POINT(Structure):
|
||||||
|
@ -320,9 +320,9 @@ class StructureTestCase(unittest.TestCase):
|
||||||
self.failUnlessEqual(cls, RuntimeError)
|
self.failUnlessEqual(cls, RuntimeError)
|
||||||
if issubclass(Exception, object):
|
if issubclass(Exception, object):
|
||||||
self.failUnlessEqual(msg,
|
self.failUnlessEqual(msg,
|
||||||
"(Phone) <type 'exceptions.ValueError'>: too many initializers")
|
"(Phone) <type 'exceptions.TypeError'>: too many initializers")
|
||||||
else:
|
else:
|
||||||
self.failUnlessEqual(msg, "(Phone) exceptions.ValueError: too many initializers")
|
self.failUnlessEqual(msg, "(Phone) exceptions.TypeError: too many initializers")
|
||||||
|
|
||||||
|
|
||||||
def get_except(self, func, *args):
|
def get_except(self, func, *args):
|
||||||
|
|
|
@ -366,6 +366,8 @@ Library
|
||||||
|
|
||||||
- Issue #1831: ctypes now raises a TypeError if conflicting positional
|
- Issue #1831: ctypes now raises a TypeError if conflicting positional
|
||||||
and named arguments are passed to a Structure or Union initializer.
|
and named arguments are passed to a Structure or Union initializer.
|
||||||
|
When too many positional arguments are passed, also a TypeError is
|
||||||
|
raised instead of a ValueError.
|
||||||
|
|
||||||
- Convert the internal ctypes array type cache to a WeakValueDict so
|
- Convert the internal ctypes array type cache to a WeakValueDict so
|
||||||
that array types do not live longer than needed.
|
that array types do not live longer than needed.
|
||||||
|
|
|
@ -3557,7 +3557,7 @@ Struct_init(PyObject *self, PyObject *args, PyObject *kwds)
|
||||||
|
|
||||||
if (PyTuple_GET_SIZE(args) > PySequence_Length(fields)) {
|
if (PyTuple_GET_SIZE(args) > PySequence_Length(fields)) {
|
||||||
Py_DECREF(fields);
|
Py_DECREF(fields);
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"too many initializers");
|
"too many initializers");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue