Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f4780d0

Browse files
committed
Fix #1753395.
1 parent 47cc2a0 commit f4780d0

1 file changed

Lines changed: 4 additions & 16 deletions

File tree

Objects/typeobject.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,28 +1561,16 @@ static PyGetSetDef subtype_getsets_weakref_only[] = {
15611561
static int
15621562
valid_identifier(PyObject *s)
15631563
{
1564-
Py_UNICODE *p;
1565-
Py_ssize_t i, n;
1566-
15671564
if (!PyUnicode_Check(s)) {
15681565
PyErr_Format(PyExc_TypeError,
15691566
"__slots__ items must be strings, not '%.200s'",
15701567
Py_Type(s)->tp_name);
15711568
return 0;
15721569
}
1573-
p = PyUnicode_AS_UNICODE(s);
1574-
n = PyUnicode_GET_SIZE(s);
1575-
/* We must reject an empty name. As a hack, we bump the
1576-
length to 1 so that the loop will balk on the trailing \0. */
1577-
if (n == 0)
1578-
n = 1;
1579-
for (i = 0; i < n; i++, p++) {
1580-
if (*p > 127 ||
1581-
(!(i == 0 ? isalpha(*p) : isalnum(*p)) && *p != '_')) {
1582-
PyErr_SetString(PyExc_TypeError,
1583-
"__slots__ must be identifiers");
1584-
return 0;
1585-
}
1570+
if (!PyUnicode_IsIdentifier(s)) {
1571+
PyErr_SetString(PyExc_TypeError,
1572+
"__slots__ must be identifiers");
1573+
return 0;
15861574
}
15871575
return 1;
15881576
}

0 commit comments

Comments
 (0)