mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Fix __reduce_ex__ and unskip tests
This commit is contained in:
5 files changed
+12
-33
No files matched your search
@@ -64,8 +64,6 @@ class TestCopy(unittest.TestCase):
|
||||
self.assertIs(y, x)
|
||||
self.assertEqual(c, [1])
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_copy_reduce(self):
|
||||
class C(object):
|
||||
def __reduce__(self):
|
||||
@@ -330,8 +328,6 @@ class TestCopy(unittest.TestCase):
|
||||
self.assertIs(y, x)
|
||||
self.assertEqual(c, [1])
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_deepcopy_reduce(self):
|
||||
class C(object):
|
||||
def __reduce__(self):
|
||||
@@ -605,8 +601,6 @@ class TestCopy(unittest.TestCase):
|
||||
|
||||
# _reconstruct()
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_reconstruct_string(self):
|
||||
class C(object):
|
||||
def __reduce__(self):
|
||||
@@ -617,8 +611,6 @@ class TestCopy(unittest.TestCase):
|
||||
y = copy.deepcopy(x)
|
||||
self.assertIs(y, x)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_reconstruct_nostate(self):
|
||||
class C(object):
|
||||
def __reduce__(self):
|
||||
@@ -630,8 +622,6 @@ class TestCopy(unittest.TestCase):
|
||||
y = copy.deepcopy(x)
|
||||
self.assertIs(y.__class__, x.__class__)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_reconstruct_state(self):
|
||||
class C(object):
|
||||
def __reduce__(self):
|
||||
@@ -646,8 +636,6 @@ class TestCopy(unittest.TestCase):
|
||||
self.assertEqual(y, x)
|
||||
self.assertIsNot(y.foo, x.foo)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_reconstruct_state_setstate(self):
|
||||
class C(object):
|
||||
def __reduce__(self):
|
||||
@@ -675,8 +663,6 @@ class TestCopy(unittest.TestCase):
|
||||
|
||||
# Additions for Python 2.3 and pickle protocol 2
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_reduce_4tuple(self):
|
||||
class C(list):
|
||||
def __reduce__(self):
|
||||
@@ -694,8 +680,6 @@ class TestCopy(unittest.TestCase):
|
||||
self.assertIsNot(x, y)
|
||||
self.assertIsNot(x[0], y[0])
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_reduce_5tuple(self):
|
||||
class C(dict):
|
||||
def __reduce__(self):
|
||||
@@ -774,8 +758,6 @@ class TestCopy(unittest.TestCase):
|
||||
self.assertIsNot(x[0], y[0])
|
||||
self.assertIsNot(x.foo, y.foo)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_copy_tuple_subclass(self):
|
||||
class C(tuple):
|
||||
pass
|
||||
@@ -784,8 +766,6 @@ class TestCopy(unittest.TestCase):
|
||||
y = copy.copy(x)
|
||||
self.assertEqual(tuple(y), (1, 2, 3))
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_deepcopy_tuple_subclass(self):
|
||||
class C(tuple):
|
||||
pass
|
||||
|
||||
@@ -711,8 +711,6 @@ class FractionTest(unittest.TestCase):
|
||||
s += num / fact * sign
|
||||
self.assertAlmostEqual(math.cos(1), s)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_copy_deepcopy_pickle(self):
|
||||
r = F(13, 7)
|
||||
dr = DummyFraction(13, 7)
|
||||
|
||||
@@ -525,8 +525,6 @@ class OperatorPickleTestCase:
|
||||
with support.swap_item(sys.modules, 'operator', self.module2):
|
||||
return pickle.loads(pickled)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_attrgetter(self):
|
||||
attrgetter = self.module.attrgetter
|
||||
class A:
|
||||
@@ -555,8 +553,6 @@ class OperatorPickleTestCase:
|
||||
self.assertEqual(repr(f2), repr(f))
|
||||
self.assertEqual(f2(a), f(a))
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_itemgetter(self):
|
||||
itemgetter = self.module.itemgetter
|
||||
a = 'ABCDE'
|
||||
@@ -572,8 +568,6 @@ class OperatorPickleTestCase:
|
||||
self.assertEqual(repr(f2), repr(f))
|
||||
self.assertEqual(f2(a), f(a))
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_methodcaller(self):
|
||||
methodcaller = self.module.methodcaller
|
||||
class A:
|
||||
|
||||
@@ -254,7 +254,8 @@ impl PyBaseObject {
|
||||
fn reduce_ex(obj: PyObjectRef, proto: usize, vm: &VirtualMachine) -> PyResult {
|
||||
if let Some(reduce) = vm.get_attribute_opt(obj.clone(), "__reduce__")? {
|
||||
let object_reduce = vm.ctx.types.object_type.get_attr("__reduce__").unwrap();
|
||||
if !reduce.is(&object_reduce) {
|
||||
let class_reduce = vm.get_attribute(obj.clone_class().into_object(), "__reduce__")?;
|
||||
if !class_reduce.is(&object_reduce) {
|
||||
return vm.invoke(&reduce, ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,10 +201,16 @@ impl PyTuple {
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn getnewargs(zelf: PyRef<Self>) -> PyTuple {
|
||||
PyTuple {
|
||||
elements: Box::new([zelf.into_object()]),
|
||||
}
|
||||
fn getnewargs(zelf: PyRef<Self>, vm: &VirtualMachine) -> (PyTupleRef,) {
|
||||
// the arguments to pass to tuple() is just one tuple - so we'll be doing tuple(tup), which
|
||||
// should just return tup, or tuplesubclass(tup), which'll copy/validate (e.g. for a
|
||||
// structseq)
|
||||
let tup_arg = if zelf.class().is(&vm.ctx.types.tuple_type) {
|
||||
zelf
|
||||
} else {
|
||||
PyTupleRef::with_elements(zelf.elements.clone().into_vec(), &vm.ctx)
|
||||
};
|
||||
(tup_arg,)
|
||||
}
|
||||
|
||||
#[pyslot]
|
||||
|
||||
Reference in new issue
Block a user