mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Allow sets to be initialized from literals.
This commit is contained in:
1 parent
c673384cc4
commit
9f3cc35e9c
2 files changed
+8
-1
No files matched your search
@@ -1,10 +1,14 @@
|
||||
|
||||
empty_set = set()
|
||||
non_empty_set = set([1,2,3])
|
||||
set_from_literal = {1,2,3}
|
||||
|
||||
assert 1 in non_empty_set
|
||||
assert 4 not in non_empty_set
|
||||
|
||||
assert 1 in set_from_literal
|
||||
assert 4 not in set_from_literal
|
||||
|
||||
# TODO: Assert that empty aruguments raises exception.
|
||||
non_empty_set.add('a')
|
||||
assert 'a' in non_empty_set
|
||||
|
||||
+4
-1
@@ -225,8 +225,11 @@ impl Frame {
|
||||
Ok(None)
|
||||
}
|
||||
bytecode::Instruction::BuildSet { size, unpack } => {
|
||||
let _elements = self.get_elements(vm, *size, *unpack)?;
|
||||
let elements = self.get_elements(vm, *size, *unpack)?;
|
||||
let py_obj = vm.ctx.new_set();
|
||||
for item in elements {
|
||||
vm.call_method(&py_obj, "add", vec![item])?;
|
||||
}
|
||||
self.push_value(py_obj);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user