Skip to content

Commit 6ca4685

Browse files
committed
__objclass__
1 parent d86b592 commit 6ca4685

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"metas",
5353
"modpow",
5454
"nanos",
55+
"objclass",
5556
"peekable",
5657
"powc",
5758
"powf",

Lib/test/test_descr.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4635,8 +4635,6 @@ def test_builtin_function_or_method(self):
46354635
# hash([].append) should not be based on hash([])
46364636
hash(l.append)
46374637

4638-
# TODO: RUSTPYTHON
4639-
@unittest.expectedFailure
46404638
def test_special_unbound_method_types(self):
46414639
# Testing objects of <type 'wrapper_descriptor'>...
46424640
self.assertTrue(list.__add__ == list.__add__)

vm/src/builtins/descriptor.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{PyStr, PyStrInterned, PyType};
22
use crate::{
3-
builtins::{builtin_func::PyNativeMethod, type_},
3+
builtins::{builtin_func::PyNativeMethod, type_, PyTypeRef},
44
class::PyClassImpl,
55
function::{FuncArgs, PyMethodDef, PyMethodFlags, PySetterValue},
66
types::{Callable, GetDescriptor, Representable, Unconstructible},
@@ -27,6 +27,7 @@ pub struct PyMethodDescriptor {
2727
pub common: PyDescriptor,
2828
pub method: &'static PyMethodDef,
2929
// vectorcall: vectorcallfunc,
30+
pub objclass: &'static Py<PyType>, // TODO: move to tp_members
3031
}
3132

3233
impl PyMethodDescriptor {
@@ -38,6 +39,7 @@ impl PyMethodDescriptor {
3839
qualname: PyRwLock::new(None),
3940
},
4041
method,
42+
objclass: typ,
4143
}
4244
}
4345
}
@@ -126,6 +128,10 @@ impl PyMethodDescriptor {
126128
.map(|signature| signature.to_string())
127129
})
128130
}
131+
#[pygetset(magic)]
132+
fn objclass(&self) -> PyTypeRef {
133+
self.objclass.to_owned()
134+
}
129135
#[pymethod(magic)]
130136
fn reduce(
131137
&self,

vm/src/builtins/getset.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! Python `attribute` descriptor class. (PyGetSet)
22
33
*/
4-
use super::PyType;
4+
use super::{PyType, PyTypeRef};
55
use crate::{
66
class::PyClassImpl,
77
function::{IntoPyGetterFunc, IntoPySetterFunc, PyGetterFunc, PySetterFunc, PySetterValue},
@@ -139,6 +139,11 @@ impl PyGetSet {
139139
fn qualname(&self) -> String {
140140
format!("{}.{}", self.class.slot_name(), self.name.clone())
141141
}
142+
143+
#[pygetset(magic)]
144+
fn objclass(&self) -> PyTypeRef {
145+
self.class.to_owned()
146+
}
142147
}
143148
impl Unconstructible for PyGetSet {}
144149

vm/src/function/method.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,8 @@ impl PyMethodDef {
170170
class: &'static Py<PyType>,
171171
) -> PyRef<PyMethodDescriptor> {
172172
debug_assert!(self.flags.contains(PyMethodFlags::METHOD));
173-
PyRef::new_ref(
174-
self.to_method(class, ctx),
175-
ctx.types.method_descriptor_type.to_owned(),
176-
None,
177-
)
173+
let method = self.to_method(class, ctx);
174+
PyRef::new_ref(method, ctx.types.method_descriptor_type.to_owned(), None)
178175
}
179176
pub fn build_bound_method(
180177
&'static self,

vm/src/vm/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ declare_const_name! {
174174
__neg__,
175175
__new__,
176176
__next__,
177+
__objclass__,
177178
__or__,
178179
__orig_bases__,
179180
__orig_class__,

0 commit comments

Comments
 (0)