mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Change sys.intern() so that unicode strings can be
interned too. Add a test for this.
This commit is contained in:
parent
360b01a663
commit
2a0c081470
2 changed files with 25 additions and 7 deletions
|
@ -266,14 +266,21 @@ sys_intern(PyObject *self, PyObject *args)
|
|||
PyObject *s;
|
||||
if (!PyArg_ParseTuple(args, "S:intern", &s))
|
||||
return NULL;
|
||||
if (!PyString_CheckExact(s)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"can't intern subclass of string");
|
||||
if (PyString_CheckExact(s)) {
|
||||
Py_INCREF(s);
|
||||
PyString_InternInPlace(&s);
|
||||
return s;
|
||||
}
|
||||
else if (PyUnicode_CheckExact(s)) {
|
||||
Py_INCREF(s);
|
||||
PyUnicode_InternInPlace(&s);
|
||||
return s;
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"can't intern %.400s", s->ob_type->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
Py_INCREF(s);
|
||||
PyString_InternInPlace(&s);
|
||||
return s;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(intern_doc,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue