Skip to content

Commit 2733b4d

Browse files
committed
Fix objtuple.tp_new so that return cloned when a parameter is tuple
1 parent 9dfb57e commit 2733b4d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Lib/test/test_tuple.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ def test_getitem_error(self):
2626
with self.assertRaisesRegex(TypeError, msg):
2727
t['a']
2828

29-
# TODO: RUSTPYTHON
30-
@unittest.expectedFailure
3129
def test_constructors(self):
3230
super().test_constructors()
3331
# calling built-in types without argument must return empty

vm/src/obj/objtuple.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use super::objsequence::get_item;
66
use super::objtype::PyClassRef;
77
use crate::function::OptionalArg;
88
use crate::pyobject::{
9-
self, BorrowValue, IntoPyObject,
9+
self, BorrowValue, IdProtocol, IntoPyObject,
1010
PyArithmaticValue::{self, *},
11-
PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
11+
PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
1212
};
1313
use crate::sequence::{self, SimpleSeq};
1414
use crate::vm::{ReprGuard, VirtualMachine};
@@ -238,6 +238,10 @@ impl PyTuple {
238238
vm: &VirtualMachine,
239239
) -> PyResult<PyTupleRef> {
240240
let elements = if let OptionalArg::Present(iterable) = iterable {
241+
if iterable.lease_class().is(&cls) {
242+
return Ok(PyRef::from_obj_unchecked(iterable));
243+
}
244+
241245
vm.extract_elements(&iterable)?
242246
} else {
243247
vec![]

0 commit comments

Comments
 (0)