object.__subclasshook__ empty classmethod

This commit is contained in:
Jeong YunWon
2019-08-15 15:45:10 +09:00
parent 49ed782098
commit 70fe087566
2 changed files with 10 additions and 1 deletions

View File

@@ -7,6 +7,10 @@ myobj = MyObject()
assert myobj == myobj
assert not myobj != myobj
object.__subclasshook__() == NotImplemented
object.__subclasshook__(1) == NotImplemented
object.__subclasshook__(1, 2) == NotImplemented
assert MyObject().__eq__(MyObject()) == NotImplemented
assert MyObject().__ne__(MyObject()) == NotImplemented
assert MyObject().__lt__(MyObject()) == NotImplemented

View File

@@ -118,6 +118,10 @@ fn object_repr(zelf: PyObjectRef, _vm: &VirtualMachine) -> String {
format!("<{} object at 0x{:x}>", zelf.class().name, zelf.get_id())
}
fn object_subclasshook(vm: &VirtualMachine, _args: PyFuncArgs) -> PyResult {
Ok(vm.ctx.not_implemented())
}
pub fn object_dir(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyList> {
let attributes: PyAttributes = objtype::get_attributes(obj.class());
@@ -179,7 +183,8 @@ pub fn init(context: &PyContext) {
"__repr__" => context.new_rustfunc(object_repr),
"__format__" => context.new_rustfunc(object_format),
"__getattribute__" => context.new_rustfunc(object_getattribute),
"__doc__" => context.new_str(object_doc.to_string())
"__subclasshook__" => context.new_classmethod(object_subclasshook),
"__doc__" => context.new_str(object_doc.to_string()),
});
}