Commit 25847f9e authored by Marius Wachtler's avatar Marius Wachtler

implement attrwrapper.has_key

parent e98abcb2
...@@ -2511,6 +2511,12 @@ public: ...@@ -2511,6 +2511,12 @@ public:
return r ? True : False; return r ? True : False;
} }
static Box* hasKey(Box* _self, Box* _key) {
if (PyErr_WarnPy3k("dict.has_key() not supported in 3.x; use the in operator", 1) < 0)
throwCAPIException();
return contains<CXX>(_self, _key);
}
static int sq_contains(Box* _self, Box* _key) noexcept { static int sq_contains(Box* _self, Box* _key) noexcept {
Box* rtn = contains<CAPI>(_self, _key); Box* rtn = contains<CAPI>(_self, _key);
if (!rtn) if (!rtn)
...@@ -4043,7 +4049,9 @@ void setupRuntime() { ...@@ -4043,7 +4049,9 @@ void setupRuntime() {
attrwrapper_cls->giveAttr("__str__", attrwrapper_cls->giveAttr("__str__",
new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::str, UNKNOWN, 1))); new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::str, UNKNOWN, 1)));
attrwrapper_cls->giveAttr( attrwrapper_cls->giveAttr(
"__contains__", new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::contains<CXX>, UNKNOWN, 2))); "__contains__", new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::contains<CXX>, BOXED_BOOL, 2)));
attrwrapper_cls->giveAttr("has_key",
new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::hasKey, BOXED_BOOL, 2)));
attrwrapper_cls->giveAttr("__eq__", attrwrapper_cls->giveAttr("__eq__",
new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::eq, UNKNOWN, 2))); new BoxedFunction(FunctionMetadata::create((void*)AttrWrapper::eq, UNKNOWN, 2)));
attrwrapper_cls->giveAttr("__ne__", attrwrapper_cls->giveAttr("__ne__",
......
...@@ -72,6 +72,7 @@ except TypeError, e: ...@@ -72,6 +72,7 @@ except TypeError, e:
print globals().get("not a real variable") print globals().get("not a real variable")
print globals().get("not a real variable", 1) print globals().get("not a real variable", 1)
print globals().has_key("C"), globals().has_key("CC")
print hex(12345) print hex(12345)
print oct(234) print oct(234)
......
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