Commit 9b5137b1 authored by Marius Wachtler's avatar Marius Wachtler

object.__setattr__ convert unicode strings

parent e3205e38
...@@ -479,9 +479,21 @@ extern "C" PyObject* PyObject_SelfIter(PyObject* obj) noexcept { ...@@ -479,9 +479,21 @@ extern "C" PyObject* PyObject_SelfIter(PyObject* obj) noexcept {
} }
extern "C" int PyObject_GenericSetAttr(PyObject* obj, PyObject* name, PyObject* value) noexcept { extern "C" int PyObject_GenericSetAttr(PyObject* obj, PyObject* name, PyObject* value) noexcept {
RELEASE_ASSERT(PyString_Check(name), ""); if (!PyString_Check(name)) {
if (PyUnicode_Check(name)) {
name = PyUnicode_AsEncodedString(name, NULL, NULL);
if (name == NULL)
return -1;
} else {
PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", Py_TYPE(name)->tp_name);
return -1;
}
}
BoxedString* str = static_cast<BoxedString*>(name); BoxedString* str = static_cast<BoxedString*>(name);
internStringMortalInplace(str); internStringMortalInplace(str);
assert(PyString_Check(name));
try { try {
if (value == NULL) if (value == NULL)
delattrGeneric(obj, str, NULL); delattrGeneric(obj, str, NULL);
......
...@@ -38,3 +38,6 @@ class Test(object): ...@@ -38,3 +38,6 @@ class Test(object):
t = Test() t = Test()
t.a = 1 t.a = 1
object.__setattr__(t, u"ustr", "42")
print t.ustr
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment