Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Lib/test/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def test_badcmp(self):
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])
Expand Down Expand Up @@ -676,7 +677,6 @@ def test_c_api(self):
class SetSubclass(set):
pass

@unittest.skip("TODO: RUSTPYTHON")
class TestSetSubclass(TestSet):
thetype = SetSubclass
basetype = set
Expand All @@ -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)
Expand All @@ -712,8 +712,6 @@ def test_singleton_empty_frozenset(self):
# 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)
Expand Down
20 changes: 17 additions & 3 deletions vm/src/builtins/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)?,
}
Expand Down