Commit 3267a579 authored by Marius Wachtler's avatar Marius Wachtler

support type(name, bases, dict) where dict has non str keys

parent f1e9b55f
......@@ -5977,13 +5977,23 @@ Box* _typeNew(BoxedClass* metatype, BoxedString* name, BoxedTuple* bases, BoxedD
made->setattr(dict_str, dict_descr, NULL);
}
bool are_all_dict_keys_strs = true;
for (const auto& p : *attr_dict) {
auto k = coerceUnicodeToStr<CXX>(p.first);
RELEASE_ASSERT(k->cls == str_cls, "%s", k->cls->tp_name);
BoxedString* s = static_cast<BoxedString*>(k);
internStringMortalInplace(s);
made->setattr(s, p.second, NULL);
if (p.first->cls != str_cls) {
are_all_dict_keys_strs = false;
break;
}
}
if (are_all_dict_keys_strs) {
for (const auto& p : *attr_dict) {
BoxedString* s = static_cast<BoxedString*>(p.first);
internStringMortalInplace(s);
made->setattr(s, p.second, NULL);
}
} else {
Box* copy = PyDict_Copy(attr_dict);
RELEASE_ASSERT(copy, "");
made->setDictBacked(copy);
}
static BoxedString* module_str = internStringImmortal("__module__");
......
......@@ -57,3 +57,9 @@ print D.__base__
print type("test", (), {})
print type("test", (), {"__module__":"fake"})
# test non str attr keys
t = type("test", (), {u"test" : 2, 1000L : 3, 1.0 : 4})
print t.__dict__[u"test"], t.test
print t.__dict__[1000L]
print t.__dict__[1.0]
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