diff --git a/src_c/color.c b/src_c/color.c index 80761a4b0d..04a6156180 100644 --- a/src_c/color.c +++ b/src_c/color.c @@ -1008,21 +1008,12 @@ _color_set_hsva(pgColorObject *color, PyObject *value, void *closure) DEL_ATTR_NOT_SUPPORTED_CHECK("hsva", value); - if (!PySequence_Check(value) || PySequence_Size(value) < 3) { + if (!PySequence_Check(value) || PySequence_Size(value) < 3 || + PySequence_Size(value) > 4) { PyErr_SetString(PyExc_ValueError, "invalid HSVA value"); return -1; } - if (PySequence_Size(value) > 4) { - if (PyErr_WarnEx( - PyExc_DeprecationWarning, - "Passing sequences of size larger than 4 is deprecated, doing " - "this will error in a future version", - 1) == -1) { - return -1; - } - } - /* H */ item = PySequence_GetItem(value, 0); if (!item || !_get_double(item, &(hsva[0])) || hsva[0] < 0 || @@ -1183,21 +1174,12 @@ _color_set_hsla(pgColorObject *color, PyObject *value, void *closure) DEL_ATTR_NOT_SUPPORTED_CHECK("hsla", value); - if (!PySequence_Check(value) || PySequence_Size(value) < 3) { + if (!PySequence_Check(value) || PySequence_Size(value) < 3 || + PySequence_Size(value) > 4) { PyErr_SetString(PyExc_ValueError, "invalid HSLA value"); return -1; } - if (PySequence_Size(value) > 4) { - if (PyErr_WarnEx( - PyExc_DeprecationWarning, - "Passing sequences of size larger than 4 is deprecated, doing " - "this will error in a future version", - 1) == -1) { - return -1; - } - } - /* H */ item = PySequence_GetItem(value, 0); if (!item || !_get_double(item, &(hsla[0])) || hsla[0] < 0 || @@ -1358,21 +1340,11 @@ _color_set_i1i2i3(pgColorObject *color, PyObject *value, void *closure) DEL_ATTR_NOT_SUPPORTED_CHECK("i1i2i3", value); - if (!PySequence_Check(value) || PySequence_Size(value) < 3) { + if (!PySequence_Check(value) || PySequence_Size(value) != 3) { PyErr_SetString(PyExc_ValueError, "invalid I1I2I3 value"); return -1; } - if (PySequence_Size(value) > 3) { - if (PyErr_WarnEx( - PyExc_DeprecationWarning, - "Passing sequences of size larger than 3 is deprecated, doing " - "this will error in a future version", - 1) == -1) { - return -1; - } - } - /* I1 */ item = PySequence_GetItem(value, 0); if (!item || !_get_double(item, &(i1i2i3[0])) || i1i2i3[0] < 0 || @@ -1440,21 +1412,11 @@ _color_set_cmy(pgColorObject *color, PyObject *value, void *closure) DEL_ATTR_NOT_SUPPORTED_CHECK("cmy", value); - if (!PySequence_Check(value) || PySequence_Size(value) < 3) { + if (!PySequence_Check(value) || PySequence_Size(value) != 3) { PyErr_SetString(PyExc_ValueError, "invalid CMY value"); return -1; } - if (PySequence_Size(value) > 3) { - if (PyErr_WarnEx( - PyExc_DeprecationWarning, - "Passing sequences of size larger than 3 is deprecated, doing " - "this will error in a future version", - 1) == -1) { - return -1; - } - } - /* I1 */ item = PySequence_GetItem(value, 0); if (!item || !_get_double(item, &(cmy[0])) || cmy[0] < 0 || cmy[0] > 1) { @@ -1510,21 +1472,12 @@ _color_set_normalized(pgColorObject *color, PyObject *value, void *closure) DEL_ATTR_NOT_SUPPORTED_CHECK("normalized", value); - if (!PySequence_Check(value) || PySequence_Size(value) < 3) { + if (!PySequence_Check(value) || PySequence_Size(value) < 3 || + PySequence_Size(value) > 4) { PyErr_SetString(PyExc_ValueError, "invalid normalized value"); return -1; } - if (PySequence_Size(value) > 4) { - if (PyErr_WarnEx( - PyExc_DeprecationWarning, - "Passing sequences of size larger than 4 is deprecated, doing " - "this will error in a future version", - 1) == -1) { - return -1; - } - } - item = PySequence_GetItem(value, 0); if (!item || !_get_double(item, &(frgba[0])) || frgba[0] < 0.0 || frgba[0] > 1.0) { diff --git a/test/color_test.py b/test/color_test.py index a34424e957..deca70957d 100644 --- a/test/color_test.py +++ b/test/color_test.py @@ -782,13 +782,12 @@ def test_from_cmy(self): self.assertEqual(expected_cmy, cmy) self.assertEqual(expected_cmy, cmy_tuple) - with self.assertWarns(DeprecationWarning): - self.assertEqual( - expected_cmy, pygame.Color.from_cmy(0.5, 0.5, 0.5, "lel", "foo") - ) - - with self.assertWarns(DeprecationWarning): - self.assertEqual(expected_cmy, pygame.Color.from_cmy((0.5, 0.5, 0.5, 0.5))) + self.assertRaises( + ValueError, lambda: pygame.Color.from_cmy(0.5, 0.5, 0.5, "lel", "foo") + ) + self.assertRaises( + ValueError, lambda: pygame.Color.from_cmy((0.5, 0.5, 0.5, 0.5)) + ) def test_from_hsva(self): hsva = pygame.Color.from_hsva(0, 100, 100, 100) @@ -799,15 +798,12 @@ def test_from_hsva(self): self.assertEqual(expected_hsva, hsva) self.assertEqual(expected_hsva, hsva_tuple) - with self.assertWarns(DeprecationWarning): - self.assertEqual( - expected_hsva, pygame.Color.from_hsva(0, 100, 100, 100, "lel", "foo") - ) - - with self.assertWarns(DeprecationWarning): - self.assertEqual( - expected_hsva, pygame.Color.from_hsva((0, 100, 100, 100, "lel")) - ) + self.assertRaises( + ValueError, lambda: pygame.Color.from_hsva(0, 100, 100, 100, "lel", "foo") + ) + self.assertRaises( + ValueError, lambda: pygame.Color.from_hsva((0, 100, 100, 100, "lel")) + ) def test_from_hsla(self): hsla = pygame.Color.from_hsla(0, 100, 100, 100) @@ -818,15 +814,12 @@ def test_from_hsla(self): self.assertEqual(expected_hsla, hsla) self.assertEqual(expected_hsla, hsla_tuple) - with self.assertWarns(DeprecationWarning): - self.assertEqual( - expected_hsla, pygame.Color.from_hsla(0, 100, 100, 100, "lel") - ) - - with self.assertWarns(DeprecationWarning): - self.assertEqual( - expected_hsla, pygame.Color.from_hsla((0, 100, 100, 100, "lel", "foo")) - ) + self.assertRaises( + ValueError, lambda: pygame.Color.from_hsla(0, 100, 100, 100, "lel") + ) + self.assertRaises( + ValueError, lambda: pygame.Color.from_hsla((0, 100, 100, 100, "lel", "foo")) + ) def test_from_i1i2i3(self): i1i2i3 = pygame.Color.from_i1i2i3(0, 0, 0) @@ -837,13 +830,10 @@ def test_from_i1i2i3(self): self.assertEqual(expected_i1i2i3, i1i2i3) self.assertEqual(expected_i1i2i3, i1i2i3_tuple) - with self.assertWarns(DeprecationWarning): - self.assertEqual( - expected_i1i2i3, pygame.Color.from_i1i2i3(0, 0, 0, "lel", "foo") - ) - - with self.assertWarns(DeprecationWarning): - self.assertEqual(expected_i1i2i3, pygame.Color.from_i1i2i3((0, 0, 0, 0))) + self.assertRaises( + ValueError, lambda: pygame.Color.from_i1i2i3(0, 0, 0, "lel", "foo") + ) + self.assertRaises(ValueError, lambda: pygame.Color.from_i1i2i3((0, 0, 0, 0))) def test_from_normalized(self): normal = pygame.Color.from_normalized(1, 1, 1, 1) @@ -854,16 +844,9 @@ def test_from_normalized(self): self.assertEqual(expected_normal, normal) self.assertEqual(expected_normal, normal_tuple) - with self.assertWarns(DeprecationWarning): - self.assertEqual( - expected_normal, pygame.Color.from_normalized(1, 1, 1, 1, "lel") - ) - - with self.assertWarns(DeprecationWarning): - self.assertEqual( - expected_normal, - pygame.Color.from_normalized((1, 1, 1, 1, "lel", "foo")), - ) + self.assertRaises( + ValueError, lambda: pygame.Color.from_normalized(1, 1, 1, 1, "lel") + ) def test_normalize(self): c = pygame.Color(204, 38, 194, 55) @@ -1062,8 +1045,10 @@ def test_normalized__sanity_testing_converted_should_equate_bar_rounding(self): def test_colorspaces_deprecated_large_sequence(self): c = pygame.Color("black") for space in ("hsla", "hsva", "i1i2i3", "cmy", "normalized"): - with self.assertWarns(DeprecationWarning): - setattr(c, space, (0, 0, 0, 0, "hehe 5th ignored member")) + with self.assertRaises(ValueError): + setattr( + c, space, (0, 0, 0, 0, "HAHAHAHAHAHA, don't ignore 5th member :)") + ) ################################################################################