Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__objclass__ #5371

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
__objclass__
  • Loading branch information
youknowone committed Jul 29, 2024
commit f6df49180b4c26fe351a9cc5cc72d3bb7edddc16
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 52,7 @@
"metas",
"modpow",
"nanos",
"objclass",
"peekable",
"powc",
"powf",
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4635,8 4635,6 @@ def test_builtin_function_or_method(self):
# 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__)
Expand Down
8 changes: 7 additions & 1 deletion vm/src/builtins/descriptor.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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 {
Expand All @@ -38,6 39,7 @@ impl PyMethodDescriptor {
qualname: PyRwLock::new(None),
},
method,
objclass: typ,
}
}
}
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion vm/src/builtins/getset.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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 {}

Expand Down
7 changes: 2 additions & 5 deletions vm/src/function/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions vm/src/vm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 174,7 @@ declare_const_name! {
__neg__,
__new__,
__next__,
__objclass__,
__or__,
__orig_bases__,
__orig_class__,
Expand Down
Loading