mirror of
https://github.com/python/cpython.git
synced 2025-11-08 21:52:45 +00:00
Fix #1753395.
This commit is contained in:
parent
47cc2a00a1
commit
f4780d03d5
1 changed files with 4 additions and 16 deletions
|
|
@ -1561,29 +1561,17 @@ static PyGetSetDef subtype_getsets_weakref_only[] = {
|
||||||
static int
|
static int
|
||||||
valid_identifier(PyObject *s)
|
valid_identifier(PyObject *s)
|
||||||
{
|
{
|
||||||
Py_UNICODE *p;
|
|
||||||
Py_ssize_t i, n;
|
|
||||||
|
|
||||||
if (!PyUnicode_Check(s)) {
|
if (!PyUnicode_Check(s)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"__slots__ items must be strings, not '%.200s'",
|
"__slots__ items must be strings, not '%.200s'",
|
||||||
Py_Type(s)->tp_name);
|
Py_Type(s)->tp_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
p = PyUnicode_AS_UNICODE(s);
|
if (!PyUnicode_IsIdentifier(s)) {
|
||||||
n = PyUnicode_GET_SIZE(s);
|
|
||||||
/* We must reject an empty name. As a hack, we bump the
|
|
||||||
length to 1 so that the loop will balk on the trailing \0. */
|
|
||||||
if (n == 0)
|
|
||||||
n = 1;
|
|
||||||
for (i = 0; i < n; i++, p++) {
|
|
||||||
if (*p > 127 ||
|
|
||||||
(!(i == 0 ? isalpha(*p) : isalnum(*p)) && *p != '_')) {
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"__slots__ must be identifiers");
|
"__slots__ must be identifiers");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue