__objclass__

This commit is contained in:
Jeong YunWon
2024-07-29 00:15:04 +09:00
committed by Jeong, YunWon
parent d86b592add
commit 6ca4685fee
6 changed files with 17 additions and 9 deletions

View File

@@ -52,6 +52,7 @@
"metas",
"modpow",
"nanos",
"objclass",
"peekable",
"powc",
"powf",

View File

@@ -4635,8 +4635,6 @@ order (MRO) for bases """
# hash([].append) should not be based on hash([])
hash(l.append)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_special_unbound_method_types(self):
# Testing objects of <type 'wrapper_descriptor'>...
self.assertTrue(list.__add__ == list.__add__)

View File

@@ -1,6 +1,6 @@
use super::{PyStr, PyStrInterned, PyType};
use crate::{
builtins::{builtin_func::PyNativeMethod, type_},
builtins::{builtin_func::PyNativeMethod, type_, PyTypeRef},
class::PyClassImpl,
function::{FuncArgs, PyMethodDef, PyMethodFlags, PySetterValue},
types::{Callable, GetDescriptor, Representable, Unconstructible},
@@ -27,6 +27,7 @@ pub struct PyMethodDescriptor {
pub common: PyDescriptor,
pub method: &'static PyMethodDef,
// vectorcall: vectorcallfunc,
pub objclass: &'static Py<PyType>, // TODO: move to tp_members
}
impl PyMethodDescriptor {
@@ -38,6 +39,7 @@ impl PyMethodDescriptor {
qualname: PyRwLock::new(None),
},
method,
objclass: typ,
}
}
}
@@ -126,6 +128,10 @@ impl PyMethodDescriptor {
.map(|signature| signature.to_string())
})
}
#[pygetset(magic)]
fn objclass(&self) -> PyTypeRef {
self.objclass.to_owned()
}
#[pymethod(magic)]
fn reduce(
&self,

View File

@@ -1,7 +1,7 @@
/*! Python `attribute` descriptor class. (PyGetSet)
*/
use super::PyType;
use super::{PyType, PyTypeRef};
use crate::{
class::PyClassImpl,
function::{IntoPyGetterFunc, IntoPySetterFunc, PyGetterFunc, PySetterFunc, PySetterValue},
@@ -139,6 +139,11 @@ impl PyGetSet {
fn qualname(&self) -> String {
format!("{}.{}", self.class.slot_name(), self.name.clone())
}
#[pygetset(magic)]
fn objclass(&self) -> PyTypeRef {
self.class.to_owned()
}
}
impl Unconstructible for PyGetSet {}

View File

@@ -170,11 +170,8 @@ impl PyMethodDef {
class: &'static Py<PyType>,
) -> PyRef<PyMethodDescriptor> {
debug_assert!(self.flags.contains(PyMethodFlags::METHOD));
PyRef::new_ref(
self.to_method(class, ctx),
ctx.types.method_descriptor_type.to_owned(),
None,
)
let method = self.to_method(class, ctx);
PyRef::new_ref(method, ctx.types.method_descriptor_type.to_owned(), None)
}
pub fn build_bound_method(
&'static self,

View File

@@ -174,6 +174,7 @@ declare_const_name! {
__neg__,
__new__,
__next__,
__objclass__,
__or__,
__orig_bases__,
__orig_class__,