Skip to content

Commit 524ff93

Browse files
authored
Merge pull request RustPython#3900 from oow214/weakref_bool
Add weakproxy bool, bytes
2 parents e5e98b7 + 4ac218f commit 524ff93

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Lib/test/test_weakref.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ def test_constructor_kwargs(self):
162162
c = C()
163163
self.assertRaises(TypeError, weakref.ref, c, callback=None)
164164

165-
# TODO: RUSTPYTHON
166-
@unittest.expectedFailure
167165
def test_proxy_ref(self):
168166
o = C()
169167
o.bar = 1
@@ -260,8 +258,6 @@ def test_basic_proxy(self):
260258
self.assertEqual(L3[:5], p3[:5])
261259
self.assertEqual(L3[2:5], p3[2:5])
262260

263-
# TODO: RUSTPYTHON
264-
@unittest.expectedFailure
265261
def test_proxy_unicode(self):
266262
# See bug 5037
267263
class C(object):
@@ -405,8 +401,6 @@ def __delitem__(self, accessor):
405401
del f[0]
406402
self.assertEqual(f.result, 0)
407403

408-
# TODO: RUSTPYTHON
409-
@unittest.expectedFailure
410404
def test_proxy_bool(self):
411405
# Test clearing of SF bug #1170766
412406
class List(list): pass

vm/src/builtins/weakproxy.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ impl PyWeakProxy {
7373
self.try_upgrade(vm)?.length(vm)
7474
}
7575

76+
#[pymethod(magic)]
77+
fn bool(&self, vm: &VirtualMachine) -> PyResult<bool> {
78+
self.try_upgrade(vm)?.is_true(vm)
79+
}
80+
81+
#[pymethod(magic)]
82+
fn bytes(&self, vm: &VirtualMachine) -> PyResult {
83+
self.try_upgrade(vm)?.bytes(vm)
84+
}
85+
7686
fn contains(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult<bool> {
7787
let obj = self.try_upgrade(vm)?;
7888
PySequence::contains(&obj, &needle, vm)

0 commit comments

Comments
 (0)