forked from Rust-related/RustPython
Make frozenset idempotent and unskip some set tests
This commit is contained in:
@@ -315,6 +315,7 @@ class TestJointOps:
|
||||
self.assertRaises(RuntimeError, s.discard, BadCmp())
|
||||
self.assertRaises(RuntimeError, s.remove, BadCmp())
|
||||
|
||||
@unittest.skip("TODO: RUSTPYTHON")
|
||||
def test_cyclical_repr(self):
|
||||
w = ReprWrapper()
|
||||
s = self.thetype([w])
|
||||
@@ -676,7 +677,6 @@ class TestSet(TestJointOps, unittest.TestCase):
|
||||
class SetSubclass(set):
|
||||
pass
|
||||
|
||||
@unittest.skip("TODO: RUSTPYTHON")
|
||||
class TestSetSubclass(TestSet):
|
||||
thetype = SetSubclass
|
||||
basetype = set
|
||||
@@ -685,9 +685,9 @@ class SetSubclassWithKeywordArgs(set):
|
||||
def __init__(self, iterable=[], newarg=None):
|
||||
set.__init__(self, iterable)
|
||||
|
||||
@unittest.skip("TODO: RUSTPYTHON")
|
||||
class TestSetSubclassWithKeywordArgs(TestSet):
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_keywords_in_subclass(self):
|
||||
'SF bug #1486663 -- this used to erroneously raise a TypeError'
|
||||
SetSubclassWithKeywordArgs(newarg=1)
|
||||
@@ -712,8 +712,6 @@ class TestFrozenSet(TestJointOps, unittest.TestCase):
|
||||
# All of the empty frozensets should have just one id()
|
||||
self.assertEqual(len(set(map(id, efs))), 1)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_constructor_identity(self):
|
||||
s = self.thetype(range(3))
|
||||
t = self.thetype(s)
|
||||
|
||||
@@ -5,10 +5,11 @@ use super::pytype::PyTypeRef;
|
||||
use crate::common::hash::PyHash;
|
||||
use crate::common::rc::PyRc;
|
||||
use crate::dictdatatype;
|
||||
use crate::function::OptionalArg::{Missing, Present};
|
||||
use crate::function::{Args, OptionalArg};
|
||||
use crate::pyobject::{
|
||||
self, BorrowValue, PyClassImpl, PyComparisonValue, PyContext, PyIterable, PyObjectRef, PyRef,
|
||||
PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
self, BorrowValue, IdProtocol, PyClassImpl, PyComparisonValue, PyContext, PyIterable,
|
||||
PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
};
|
||||
use crate::slots::{Comparable, Hashable, Iterable, PyComparisonOp, PyIter, Unhashable};
|
||||
use crate::vm::{ReprGuard, VirtualMachine};
|
||||
@@ -569,9 +570,22 @@ impl PyFrozenSet {
|
||||
#[pyslot]
|
||||
fn tp_new(
|
||||
cls: PyTypeRef,
|
||||
iterable: OptionalArg<PyIterable>,
|
||||
iterable: OptionalArg<PyObjectRef>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyRef<Self>> {
|
||||
let iterable = if let Present(iterable) = iterable {
|
||||
if cls.is(&vm.ctx.types.frozenset_type) {
|
||||
match iterable.downcast_exact::<PyFrozenSet>(vm) {
|
||||
Ok(iter) => return Ok(iter),
|
||||
Err(iterable) => Present(PyIterable::try_from_object(vm, iterable)?),
|
||||
}
|
||||
} else {
|
||||
Present(PyIterable::try_from_object(vm, iterable)?)
|
||||
}
|
||||
} else {
|
||||
Missing
|
||||
};
|
||||
|
||||
Self {
|
||||
inner: PySetInner::from_arg(iterable, vm)?,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user