|
1 |
| -use once_cell::sync::Lazy; |
2 |
| - |
3 | 1 | use super::{PyStr, PyStrRef, PyType, PyTypeRef, PyWeak};
|
4 | 2 | use crate::{
|
5 | 3 | atomic_func,
|
6 | 4 | class::PyClassImpl,
|
| 5 | + common::hash::PyHash, |
7 | 6 | function::{OptionalArg, PyComparisonValue, PySetterValue},
|
8 | 7 | protocol::{PyIter, PyIterReturn, PyMappingMethods, PySequenceMethods},
|
9 | 8 | types::{
|
10 |
| - AsMapping, AsSequence, Comparable, Constructor, GetAttr, IterNext, Iterable, |
| 9 | + AsMapping, AsSequence, Comparable, Constructor, GetAttr, Hashable, IterNext, Iterable, |
11 | 10 | PyComparisonOp, Representable, SetAttr,
|
12 | 11 | },
|
13 | 12 | Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
14 | 13 | };
|
| 14 | +use once_cell::sync::Lazy; |
15 | 15 |
|
16 |
| -#[pyclass(module = false, name = "weakproxy")] |
| 16 | +#[pyclass(module = false, name = "weakproxy", unhashable = true)] |
17 | 17 | #[derive(Debug)]
|
18 | 18 | pub struct PyWeakProxy {
|
19 | 19 | weak: PyRef<PyWeak>,
|
@@ -123,6 +123,7 @@ impl PyWeakProxy {
|
123 | 123 | obj.del_item(&*needle, vm)
|
124 | 124 | }
|
125 | 125 | }
|
| 126 | + |
126 | 127 | impl Iterable for PyWeakProxy {
|
127 | 128 | fn iter(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult {
|
128 | 129 | let obj = zelf.try_upgrade(vm)?;
|
@@ -226,3 +227,9 @@ impl Representable for PyWeakProxy {
|
226 | 227 | pub fn init(context: &Context) {
|
227 | 228 | PyWeakProxy::extend_class(context, context.types.weakproxy_type);
|
228 | 229 | }
|
| 230 | + |
| 231 | +impl Hashable for PyWeakProxy { |
| 232 | + fn hash(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyHash> { |
| 233 | + zelf.try_upgrade(vm)?.hash(vm) |
| 234 | + } |
| 235 | +} |
0 commit comments