From 0f2bd598372c585e2e9b615eebed0a428c32abe5 Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Tue, 24 Nov 2020 22:31:26 -0600 Subject: [PATCH 1/4] Make `type()` bases arg only take tuples --- vm/src/builtins/pytype.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vm/src/builtins/pytype.rs b/vm/src/builtins/pytype.rs index 498f0bb361..27c5706f03 100644 --- a/vm/src/builtins/pytype.rs +++ b/vm/src/builtins/pytype.rs @@ -15,6 +15,7 @@ use super::pystr::PyStrRef; use super::staticmethod::PyStaticMethod; use super::tuple::PyTuple; use super::weakref::PyWeak; +use crate::builtins::tuple::PyTupleRef; use crate::function::{FuncArgs, KwArgs}; use crate::pyobject::{ BorrowValue, Either, IdProtocol, PyAttributes, PyClassImpl, PyContext, PyIterable, PyLease, @@ -417,9 +418,12 @@ impl PyType { })); } - let (name, bases, dict, kwargs): (PyStrRef, PyIterable, PyDictRef, KwArgs) = + let (name, bases, dict, kwargs): (PyStrRef, PyTupleRef, PyDictRef, KwArgs) = args.clone().bind(vm)?; + // TODO: This is kind of a hack because we lose type information only to redo it + let bases: PyIterable = + PyIterable::try_from_object(vm, bases.into_object()).unwrap(); let bases: Vec = bases.iter(vm)?.collect::, _>>()?; let (metatype, base, bases) = if bases.is_empty() { let base = vm.ctx.types.object_type.clone(); From a6afbdf91191d4a13fc80ff356efd7ee82ac50f6 Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Thu, 10 Dec 2020 22:30:27 -0600 Subject: [PATCH 2/4] Update --- vm/src/builtins/pytype.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/vm/src/builtins/pytype.rs b/vm/src/builtins/pytype.rs index 27c5706f03..34eb780c49 100644 --- a/vm/src/builtins/pytype.rs +++ b/vm/src/builtins/pytype.rs @@ -15,7 +15,7 @@ use super::pystr::PyStrRef; use super::staticmethod::PyStaticMethod; use super::tuple::PyTuple; use super::weakref::PyWeak; -use crate::builtins::tuple::PyTupleRef; +use crate::builtins::tuple::{PyTupleRef, PyTupleTyped}; use crate::function::{FuncArgs, KwArgs}; use crate::pyobject::{ BorrowValue, Either, IdProtocol, PyAttributes, PyClassImpl, PyContext, PyIterable, PyLease, @@ -418,13 +418,10 @@ impl PyType { })); } - let (name, bases, dict, kwargs): (PyStrRef, PyTupleRef, PyDictRef, KwArgs) = + let (name, bases, dict, kwargs): (PyStrRef, PyTupleTyped, PyDictRef, KwArgs) = args.clone().bind(vm)?; - // TODO: This is kind of a hack because we lose type information only to redo it - let bases: PyIterable = - PyIterable::try_from_object(vm, bases.into_object()).unwrap(); - let bases: Vec = bases.iter(vm)?.collect::, _>>()?; + let bases = bases.borrow_value().iter().cloned().collect::>(); let (metatype, base, bases) = if bases.is_empty() { let base = vm.ctx.types.object_type.clone(); (metatype, base.clone(), vec![base]) From 92437160c74df017e4e9029f8f610e44fb376cc6 Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Fri, 11 Dec 2020 20:55:02 -0600 Subject: [PATCH 3/4] Fix clippy --- vm/src/builtins/pytype.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vm/src/builtins/pytype.rs b/vm/src/builtins/pytype.rs index 34eb780c49..4e9a124465 100644 --- a/vm/src/builtins/pytype.rs +++ b/vm/src/builtins/pytype.rs @@ -15,10 +15,10 @@ use super::pystr::PyStrRef; use super::staticmethod::PyStaticMethod; use super::tuple::PyTuple; use super::weakref::PyWeak; -use crate::builtins::tuple::{PyTupleRef, PyTupleTyped}; +use crate::builtins::tuple::PyTupleTyped; use crate::function::{FuncArgs, KwArgs}; use crate::pyobject::{ - BorrowValue, Either, IdProtocol, PyAttributes, PyClassImpl, PyContext, PyIterable, PyLease, + BorrowValue, Either, IdProtocol, PyAttributes, PyClassImpl, PyContext, PyLease, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, }; use crate::slots::{self, Callable, PyTpFlags, PyTypeSlots, SlotGetattro}; @@ -421,7 +421,7 @@ impl PyType { let (name, bases, dict, kwargs): (PyStrRef, PyTupleTyped, PyDictRef, KwArgs) = args.clone().bind(vm)?; - let bases = bases.borrow_value().iter().cloned().collect::>(); + let bases = bases.borrow_value().to_vec(); let (metatype, base, bases) = if bases.is_empty() { let base = vm.ctx.types.object_type.clone(); (metatype, base.clone(), vec![base]) From 6cb89fbdca668b47abf68106ed2d73a64c7db707 Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Fri, 11 Dec 2020 22:02:55 -0600 Subject: [PATCH 4/4] Formaat --- vm/src/builtins/pytype.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/src/builtins/pytype.rs b/vm/src/builtins/pytype.rs index 4e9a124465..bed1d5aaea 100644 --- a/vm/src/builtins/pytype.rs +++ b/vm/src/builtins/pytype.rs @@ -18,8 +18,8 @@ use super::weakref::PyWeak; use crate::builtins::tuple::PyTupleTyped; use crate::function::{FuncArgs, KwArgs}; use crate::pyobject::{ - BorrowValue, Either, IdProtocol, PyAttributes, PyClassImpl, PyContext, PyLease, - PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, + BorrowValue, Either, IdProtocol, PyAttributes, PyClassImpl, PyContext, PyLease, PyObjectRef, + PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, }; use crate::slots::{self, Callable, PyTpFlags, PyTypeSlots, SlotGetattro}; use crate::vm::VirtualMachine;