Skip to content

Commit eecca9f

Browse files
committed
Deprecation passing out of range range colorspace
1 parent 956a0b6 commit eecca9f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src_c/color.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,16 @@ _color_set_hsva(pgColorObject *color, PyObject *value, void *closure)
11441144
return -1;
11451145
}
11461146

1147+
if (PySequence_Size(value) > 4) {
1148+
if (PyErr_WarnEx(
1149+
PyExc_DeprecationWarning,
1150+
"Passing sequences of size larger than 4 is deprecated, doing "
1151+
"this will error in a future version",
1152+
1) == -1) {
1153+
return -1;
1154+
}
1155+
}
1156+
11471157
/* H */
11481158
item = PySequence_GetItem(value, 0);
11491159
if (!item || !_get_double(item, &(hsva[0])) || hsva[0] < 0 ||
@@ -1309,6 +1319,16 @@ _color_set_hsla(pgColorObject *color, PyObject *value, void *closure)
13091319
return -1;
13101320
}
13111321

1322+
if (PySequence_Size(value) > 4) {
1323+
if (PyErr_WarnEx(
1324+
PyExc_DeprecationWarning,
1325+
"Passing sequences of size larger than 4 is deprecated, doing "
1326+
"this will error in a future version",
1327+
1) == -1) {
1328+
return -1;
1329+
}
1330+
}
1331+
13121332
/* H */
13131333
item = PySequence_GetItem(value, 0);
13141334
if (!item || !_get_double(item, &(hsla[0])) || hsla[0] < 0 ||
@@ -1469,6 +1489,21 @@ _color_set_i1i2i3(pgColorObject *color, PyObject *value, void *closure)
14691489

14701490
DEL_ATTR_NOT_SUPPORTED_CHECK("i1i2i3", value);
14711491

1492+
if (!PySequence_Check(value) || PySequence_Size(value) < 3) {
1493+
PyErr_SetString(PyExc_ValueError, "invalid I1I2I3 value");
1494+
return -1;
1495+
}
1496+
1497+
if (PySequence_Size(value) > 3) {
1498+
if (PyErr_WarnEx(
1499+
PyExc_DeprecationWarning,
1500+
"Passing sequences of size larger than 3 is deprecated, doing "
1501+
"this will error in a future version",
1502+
1) == -1) {
1503+
return -1;
1504+
}
1505+
}
1506+
14721507
/* I1 */
14731508
item = PySequence_GetItem(value, 0);
14741509
if (!item || !_get_double(item, &(i1i2i3[0])) || i1i2i3[0] < 0 ||
@@ -1536,6 +1571,21 @@ _color_set_cmy(pgColorObject *color, PyObject *value, void *closure)
15361571

15371572
DEL_ATTR_NOT_SUPPORTED_CHECK("cmy", value);
15381573

1574+
if (!PySequence_Check(value) || PySequence_Size(value) < 3) {
1575+
PyErr_SetString(PyExc_ValueError, "invalid CMY value");
1576+
return -1;
1577+
}
1578+
1579+
if (PySequence_Size(value) > 3) {
1580+
if (PyErr_WarnEx(
1581+
PyExc_DeprecationWarning,
1582+
"Passing sequences of size larger than 3 is deprecated, doing "
1583+
"this will error in a future version",
1584+
1) == -1) {
1585+
return -1;
1586+
}
1587+
}
1588+
15391589
/* I1 */
15401590
item = PySequence_GetItem(value, 0);
15411591
if (!item || !_get_double(item, &(cmy[0])) || cmy[0] < 0 || cmy[0] > 1) {

0 commit comments

Comments
 (0)