Commit 7ea200d7 authored by asaka's avatar asaka

add type check in viewkeys / viewvalues / viewitems method on dict

parent ca306a4c
......@@ -91,16 +91,28 @@ Box* dictKeys(BoxedDict* self) {
}
Box* dictViewKeys(BoxedDict* self) {
if (!isSubclass(self->cls, dict_cls)) {
raiseExcHelper(TypeError, "descriptor 'viewkeys' requires a 'dict' object but received a '%s'",
getTypeName(self)->c_str());
}
BoxedDictView* rtn = new BoxedDictView(self, dict_keys_cls);
return rtn;
}
Box* dictViewValues(BoxedDict* self) {
if (!isSubclass(self->cls, dict_cls)) {
raiseExcHelper(TypeError, "descriptor 'viewvalues' requires a 'dict' object but received a '%s'",
getTypeName(self)->c_str());
}
BoxedDictView* rtn = new BoxedDictView(self, dict_values_cls);
return rtn;
}
Box* dictViewItems(BoxedDict* self) {
if (!isSubclass(self->cls, dict_cls)) {
raiseExcHelper(TypeError, "descriptor 'viewitems' requires a 'dict' object but received a '%s'",
getTypeName(self)->c_str());
}
BoxedDictView* rtn = new BoxedDictView(self, dict_items_cls);
return rtn;
}
......
......@@ -197,13 +197,19 @@ print sorted(d.items())
# viewkeys / viewvalues / viewitems
d = {}
keys = d.keys()
viewkeys = d.viewkeys()
print list(d.viewkeys())
print list(d.viewvalues())
print list(d.viewitems())
print 'keys of d: ', keys
print 'viewkeys of d: ', list(viewkeys)
d['a'] = 1
print list(d.viewkeys())
print list(d.viewvalues())
print list(d.viewitems())
print 'keys of d: ', keys
print 'viewkeys of d: ', list(viewkeys)
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