Cleanup previous PR

This commit is contained in:
Kovid Goyal
2026-03-16 17:38:14 +05:30
parent d97850274f
commit 83160c10c4
2 changed files with 11 additions and 10 deletions

View File

@@ -696,19 +696,19 @@ color_vectorcall(PyObject *type UNUSED, PyObject *const *args, size_t nargsf, Py
rgba[i] = (unsigned char)val;
}
if (kwnames) {
static const char *const kwnames_list[] = {"red", "green", "blue", "alpha"};
const Py_ssize_t nkwargs = PyTuple_GET_SIZE(kwnames);
for (Py_ssize_t i = 0; i < nkwargs; i++) {
const unsigned num = PyTuple_GET_SIZE(kwnames);
for (unsigned i = 0; i < num; i++) {
const char *name = PyUnicode_AsUTF8(PyTuple_GET_ITEM(kwnames, i));
if (!name) return NULL;
int idx = -1;
for (int j = 0; j < 4; j++) {
if (strcmp(name, kwnames_list[j]) == 0) { idx = j; break; }
}
if (idx < 0) {
PyErr_Format(PyExc_TypeError, "Color() got an unexpected keyword argument '%s'", name);
return NULL;
int idx;
#define C(ch, i, expected) case ch: idx = i; if (strcmp(name, expected) != 0) { \
PyErr_Format(PyExc_TypeError, "Color() got an unexpected keyword argument '%s'", name); return NULL; }; break;
switch(name[0]) {
C('r', 0, "red"); C('g', 1, "green"); C('b', 2, "blue"); C('a', 3, "alpha");
default:
PyErr_Format(PyExc_TypeError, "Color() got an unexpected keyword argument '%s'", name); return NULL;
}
#undef C
if (idx < nargs) {
PyErr_Format(PyExc_TypeError, "Color() got multiple values for argument '%s'", name);
return NULL;

View File

@@ -66,6 +66,7 @@ class TestDataTypes(BaseTest):
def c(spec, r=0, g=0, b=0, a=0):
c = to_color(spec)
self.ae(Color(r, g, b, a), c, spec)
self.ae(Color(r, green=g, alpha=a, blue=b), c, spec)
c('#eee # comment', 0xee, 0xee, 0xee)
c('#234567', 0x23, 0x45, 0x67)