Skip to content

Commit 0e72ba8

Browse files
authored
implement PyObject_Type and PyObject_TypeCheck (RustPython#5091)
1 parent 4e6172b commit 0e72ba8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

vm/src/protocol/object.rs

+6
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,14 @@ impl PyObject {
559559

560560
// type protocol
561561
// PyObject *PyObject_Type(PyObject *o)
562+
pub fn obj_type(&self) -> PyObjectRef {
563+
self.class().to_owned().into()
564+
}
562565

563566
// int PyObject_TypeCheck(PyObject *o, PyTypeObject *type)
567+
pub fn type_check(&self, typ: PyTypeRef) -> bool {
568+
self.class().fast_isinstance(&typ)
569+
}
564570

565571
pub fn length_opt(&self, vm: &VirtualMachine) -> Option<PyResult<usize>> {
566572
self.to_sequence(vm)

0 commit comments

Comments
 (0)