Skip to content

Inspect arg as Python object, instead of using PyErr_Clear()#9726

Open
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:clear
Open

Inspect arg as Python object, instead of using PyErr_Clear()#9726
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:clear

Conversation

@radarhere

@radarhere radarhere commented Jun 28, 2026

Copy link
Copy Markdown
Member

In _convert_transparent(), instead of failing a call to PyArg_ParseTuple(), calling PyErr_Clear() afterwards and then trying again,

Pillow/src/_imaging.c

Lines 1084 to 1089 in 095bbc3

if (PyArg_ParseTuple(args, "s(iii)", &mode_name, &r, &g, &b)) {
const ModeID mode = findModeID(mode_name);
return PyImagingNew(ImagingConvertTransparent(self->image, mode, r, g, b));
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "si", &mode_name, &r)) {

an alternative strategy would be to parse the second argument as a PyObject ("O") and then check if it is a tuple or not.

A similar change could be made in _convert_matrix().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant