From 2e9acb3035d93e36c315fe3068b7f52ff57b09aa Mon Sep 17 00:00:00 2001 From: jfh Date: Thu, 17 Jun 2021 12:25:59 +0300 Subject: [PATCH] Make tuple() return empty_tuple --- vm/src/builtins/tuple.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vm/src/builtins/tuple.rs b/vm/src/builtins/tuple.rs index 9f82122eb..0940271e0 100644 --- a/vm/src/builtins/tuple.rs +++ b/vm/src/builtins/tuple.rs @@ -258,10 +258,16 @@ impl PyTuple { vm.extract_elements(&iterable)? } else { vec![] + }; + // Return empty tuple only for exact tuple types if the iterable is empty. + if elements.is_empty() && cls.is(&vm.ctx.types.tuple_type) { + Ok(vm.ctx.empty_tuple.clone()) + } else { + Self { + elements: elements.into_boxed_slice(), + } + .into_ref_with_type(vm, cls) } - .into_boxed_slice(); - - Self { elements }.into_ref_with_type(vm, cls) } }