mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 11:14:38 +08:00
Merge pull request #2082 from clemado1/tuple_tp_new
Fix objtuple.tp_new so that return cloned when a parameter is tuple
This commit is contained in:
2 files changed
+6
-4
No files matched your search
@@ -26,8 +26,6 @@ class TupleTest(seq_tests.CommonTest):
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
t['a']
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_constructors(self):
|
||||
super().test_constructors()
|
||||
# calling built-in types without argument must return empty
|
||||
|
||||
@@ -6,9 +6,9 @@ use super::objsequence::get_item;
|
||||
use super::objtype::PyClassRef;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::pyobject::{
|
||||
self, BorrowValue, IntoPyObject,
|
||||
self, BorrowValue, IdProtocol, IntoPyObject,
|
||||
PyArithmaticValue::{self, *},
|
||||
PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
};
|
||||
use crate::sequence::{self, SimpleSeq};
|
||||
use crate::vm::{ReprGuard, VirtualMachine};
|
||||
@@ -238,6 +238,10 @@ impl PyTuple {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyTupleRef> {
|
||||
let elements = if let OptionalArg::Present(iterable) = iterable {
|
||||
if iterable.lease_class().is(&cls) {
|
||||
return Ok(PyRef::from_obj_unchecked(iterable));
|
||||
}
|
||||
|
||||
vm.extract_elements(&iterable)?
|
||||
} else {
|
||||
vec![]
|
||||
|
||||
Reference in new issue
Block a user