|
1 | 1 | use super::{PyStrRef, PyType, PyTypeRef, PyWeak};
|
2 | 2 | use crate::{
|
3 | 3 | class::PyClassImpl,
|
4 |
| - function::OptionalArg, |
| 4 | + function::{OptionalArg, PyComparisonValue}, |
5 | 5 | protocol::{PyMappingMethods, PySequence, PySequenceMethods},
|
6 |
| - types::{AsMapping, AsSequence, Constructor, GetAttr, SetAttr}, |
7 |
| - Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, |
| 6 | + types::{AsMapping, AsSequence, Comparable, Constructor, GetAttr, PyComparisonOp, SetAttr}, |
| 7 | + Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, |
8 | 8 | };
|
9 | 9 |
|
10 | 10 | #[pyclass(module = false, name = "weakproxy")]
|
@@ -83,6 +83,11 @@ impl PyWeakProxy {
|
83 | 83 | self.try_upgrade(vm)?.bytes(vm)
|
84 | 84 | }
|
85 | 85 |
|
| 86 | + #[pymethod(magic)] |
| 87 | + fn repr(&self, vm: &VirtualMachine) -> PyResult<PyStrRef> { |
| 88 | + self.try_upgrade(vm)?.repr(vm) |
| 89 | + } |
| 90 | + |
86 | 91 | fn contains(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult<bool> {
|
87 | 92 | let obj = self.try_upgrade(vm)?;
|
88 | 93 | PySequence::contains(&obj, &needle, vm)
|
@@ -136,6 +141,20 @@ impl SetAttr for PyWeakProxy {
|
136 | 141 | }
|
137 | 142 | }
|
138 | 143 |
|
| 144 | +impl Comparable for PyWeakProxy { |
| 145 | + fn cmp( |
| 146 | + zelf: &crate::Py<Self>, |
| 147 | + other: &PyObject, |
| 148 | + op: PyComparisonOp, |
| 149 | + vm: &VirtualMachine, |
| 150 | + ) -> PyResult<PyComparisonValue> { |
| 151 | + let obj = zelf.try_upgrade(vm)?; |
| 152 | + Ok(PyComparisonValue::Implemented( |
| 153 | + obj.rich_compare_bool(other, op, vm)?, |
| 154 | + )) |
| 155 | + } |
| 156 | +} |
| 157 | + |
139 | 158 | impl AsSequence for PyWeakProxy {
|
140 | 159 | const AS_SEQUENCE: PySequenceMethods = PySequenceMethods {
|
141 | 160 | length: Some(|seq, vm| Self::sequence_downcast(seq).len(vm)),
|
|
0 commit comments