Skip to content

Commit 70fe087

Browse files
committed
object.__subclasshook__ empty classmethod
1 parent 49ed782 commit 70fe087

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

tests/snippets/object.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ class MyObject:
77
assert myobj == myobj
88
assert not myobj != myobj
99

10+
object.__subclasshook__() == NotImplemented
11+
object.__subclasshook__(1) == NotImplemented
12+
object.__subclasshook__(1, 2) == NotImplemented
13+
1014
assert MyObject().__eq__(MyObject()) == NotImplemented
1115
assert MyObject().__ne__(MyObject()) == NotImplemented
1216
assert MyObject().__lt__(MyObject()) == NotImplemented

vm/src/obj/objobject.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ fn object_repr(zelf: PyObjectRef, _vm: &VirtualMachine) -> String {
118118
format!("<{} object at 0x{:x}>", zelf.class().name, zelf.get_id())
119119
}
120120

121+
fn object_subclasshook(vm: &VirtualMachine, _args: PyFuncArgs) -> PyResult {
122+
Ok(vm.ctx.not_implemented())
123+
}
124+
121125
pub fn object_dir(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyList> {
122126
let attributes: PyAttributes = objtype::get_attributes(obj.class());
123127

@@ -179,7 +183,8 @@ pub fn init(context: &PyContext) {
179183
"__repr__" => context.new_rustfunc(object_repr),
180184
"__format__" => context.new_rustfunc(object_format),
181185
"__getattribute__" => context.new_rustfunc(object_getattribute),
182-
"__doc__" => context.new_str(object_doc.to_string())
186+
"__subclasshook__" => context.new_classmethod(object_subclasshook),
187+
"__doc__" => context.new_str(object_doc.to_string()),
183188
});
184189
}
185190

0 commit comments

Comments
 (0)