mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Merge pull request #3221 from youknowone/pyref-intoobject
Remove PyRef::into_object()
This commit is contained in:
74 files changed
+441
-455
No files matched your search
@@ -38,7 +38,7 @@ pub(crate) fn impl_pystruct_sequence(input: DeriveInput) -> Result<TokenStream>
|
||||
}
|
||||
impl ::rustpython_vm::function::IntoPyObject for #ty {
|
||||
fn into_pyobject(self, vm: &::rustpython_vm::VirtualMachine) -> ::rustpython_vm::PyObjectRef {
|
||||
::rustpython_vm::PyStructSequence::into_struct_sequence(self, vm).into_object()
|
||||
::rustpython_vm::PyStructSequence::into_struct_sequence(self, vm).into()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+2
-1
@@ -640,7 +640,8 @@ fn get_importer(path: &str, vm: &VirtualMachine) -> PyResult<Option<PyObjectRef>
|
||||
let path = vm.ctx.new_utf8_str(path);
|
||||
let path_hooks = vm.get_attribute(vm.sys_module.clone(), "path_hooks")?;
|
||||
let mut importer = None;
|
||||
for path_hook in vm.extract_elements(&path_hooks)? {
|
||||
let path_hooks: Vec<PyObjectRef> = vm.extract_elements(&path_hooks)?;
|
||||
for path_hook in path_hooks {
|
||||
match vm.invoke(&path_hook, (path.clone(),)) {
|
||||
Ok(imp) => {
|
||||
importer = Some(imp);
|
||||
|
||||
+1
-1
@@ -665,7 +665,7 @@ mod array {
|
||||
}
|
||||
|
||||
let zelf = Self::from(array).into_ref_with_type(vm, cls)?;
|
||||
Ok(zelf.into_object())
|
||||
Ok(zelf.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-7
@@ -12,22 +12,20 @@ mod decl {
|
||||
fn dis(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
|
||||
let co = if let Ok(co) = vm.get_attribute(obj.clone(), "__code__") {
|
||||
// Method or function:
|
||||
co
|
||||
PyRef::try_from_object(vm, co)?
|
||||
} else if let Ok(co_str) = PyStrRef::try_from_object(vm, obj.clone()) {
|
||||
// String:
|
||||
vm.compile(co_str.as_str(), compile::Mode::Exec, "<dis>".to_owned())
|
||||
.map_err(|err| vm.new_syntax_error(&err))?
|
||||
.into_object()
|
||||
} else {
|
||||
obj
|
||||
PyRef::try_from_object(vm, obj)?
|
||||
};
|
||||
disassemble(co, vm)
|
||||
disassemble(co)
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn disassemble(co: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
|
||||
let code = PyRef::<PyCode>::try_from_object(vm, co)?;
|
||||
print!("{}", &code.code);
|
||||
fn disassemble(co: PyRef<PyCode>) -> PyResult<()> {
|
||||
print!("{}", &co.code);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -48,9 +48,7 @@ mod hashlib {
|
||||
|
||||
#[pyslot]
|
||||
fn slot_new(_cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
Ok(PyHasher::new("md5", HashWrapper::md5())
|
||||
.into_ref(vm)
|
||||
.into_object())
|
||||
Ok(PyHasher::new("md5", HashWrapper::md5()).into_object(vm))
|
||||
}
|
||||
|
||||
#[pyproperty]
|
||||
|
||||
+3
-17
@@ -90,8 +90,7 @@ mod _json {
|
||||
vm.invoke(
|
||||
&parse_obj,
|
||||
(
|
||||
vm.ctx
|
||||
.new_tuple(vec![pystr.into_object(), vm.ctx.new_int(next_idx)]),
|
||||
(pystr, next_idx),
|
||||
self.strict,
|
||||
scan_once,
|
||||
self.object_hook.clone(),
|
||||
@@ -105,14 +104,7 @@ mod _json {
|
||||
// TODO: parse the array in rust
|
||||
let parse_array = vm.get_attribute(self.ctx.clone(), "parse_array")?;
|
||||
return PyIterReturn::from_pyresult(
|
||||
vm.invoke(
|
||||
&parse_array,
|
||||
vec![
|
||||
vm.ctx
|
||||
.new_tuple(vec![pystr.into_object(), vm.ctx.new_int(next_idx)]),
|
||||
scan_once,
|
||||
],
|
||||
),
|
||||
vm.invoke(&parse_array, ((pystr, next_idx), scan_once)),
|
||||
vm,
|
||||
);
|
||||
}
|
||||
@@ -207,13 +199,7 @@ mod _json {
|
||||
if idx > 0 && chars.nth(idx - 1).is_none() {
|
||||
return Ok(PyIterReturn::StopIteration(Some(vm.ctx.new_int(idx))));
|
||||
}
|
||||
zelf.parse(
|
||||
chars.as_str(),
|
||||
pystr.clone(),
|
||||
idx,
|
||||
zelf.clone().into_object(),
|
||||
vm,
|
||||
)
|
||||
zelf.parse(chars.as_str(), pystr.clone(), idx, zelf.clone().into(), vm)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ mod _pyexpat {
|
||||
}
|
||||
|
||||
let name_str = PyStr::from(name.local_name).into_ref(vm);
|
||||
invoke_handler(vm, &self.start_element, (name_str, dict.into_object()));
|
||||
invoke_handler(vm, &self.start_element, (name_str, dict));
|
||||
}
|
||||
Ok(XmlEvent::EndElement { name, .. }) => {
|
||||
let name_str = PyStr::from(name.local_name).into_ref(vm);
|
||||
|
||||
+19
-15
@@ -3,15 +3,15 @@ pub(crate) use re::make_module;
|
||||
#[pymodule]
|
||||
mod re {
|
||||
/*
|
||||
* Regular expressions.
|
||||
*
|
||||
* This module fits the python re interface onto the rust regular expression
|
||||
* system.
|
||||
*/
|
||||
use crate::{
|
||||
builtins::{PyInt, PyIntRef, PyStr, PyStrRef, PyTypeRef},
|
||||
* Regular expressions.
|
||||
*
|
||||
* This module fits the python re interface onto the rust regular expression
|
||||
* system.
|
||||
*/
|
||||
use crate::vm::{
|
||||
builtins::{PyInt, PyIntRef, PyStr, PyStrRef},
|
||||
function::{IntoPyObject, OptionalArg, PosArgs},
|
||||
PyClassImpl, PyObjectRef, PyResult, PyValue, StaticType, TryFromObject, VirtualMachine,
|
||||
match_class, PyObjectRef, PyResult, PyValue, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use num_traits::Signed;
|
||||
use regex::bytes::{Captures, Regex, RegexBuilder};
|
||||
@@ -91,8 +91,8 @@ mod re {
|
||||
// type PyPatternRef = PyRef<PyPattern>;
|
||||
// type PyMatchRef = PyRef<PyMatch>;
|
||||
|
||||
#[pyfunction]
|
||||
fn match(
|
||||
#[pyfunction(name = "match")]
|
||||
fn match_(
|
||||
pattern: PyStrRef,
|
||||
string: PyStrRef,
|
||||
flags: OptionalArg<usize>,
|
||||
@@ -222,12 +222,12 @@ mod re {
|
||||
) -> PyResult {
|
||||
if maxsplit
|
||||
.as_ref()
|
||||
.map_or(false, |i| i.as_str().is_negative())
|
||||
.map_or(false, |i| i.as_bigint().is_negative())
|
||||
{
|
||||
return Ok(vm.ctx.new_list(vec![search_text.into_object()]));
|
||||
return Ok(vm.ctx.new_list(vec![search_text.into()]));
|
||||
}
|
||||
let maxsplit = maxsplit
|
||||
.map(|i| usize::try_from_object(vm, i.into_object()))
|
||||
.map(|i| i.try_to_primitive::<usize>(vm))
|
||||
.transpose()?
|
||||
.unwrap_or(0);
|
||||
let text = search_text.as_str().as_bytes();
|
||||
@@ -388,10 +388,14 @@ mod re {
|
||||
self.haystack.as_str()[bounds].to_owned()
|
||||
}
|
||||
|
||||
fn get_bounds(&self, id: PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<Range<usize>>> {
|
||||
fn get_bounds(
|
||||
&self,
|
||||
id: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<Option<Range<usize>>> {
|
||||
match_class!(match id {
|
||||
i @ PyInt => {
|
||||
let i = usize::try_from_object(vm, i.into_object())?;
|
||||
let i = usize::try_from_object(vm, i.into())?;
|
||||
let capture = self
|
||||
.captures
|
||||
.get(i)
|
||||
|
||||
+2
-2
@@ -197,7 +197,7 @@ fn _ssl_enum_certificates(store_name: PyStrRef, vm: &VirtualMachine) -> PyResult
|
||||
PyFrozenSet::from_iter(vm, oids.into_iter().map(|oid| vm.ctx.new_utf8_str(oid)))
|
||||
.unwrap()
|
||||
.into_ref(vm)
|
||||
.into_object()
|
||||
.into()
|
||||
}
|
||||
};
|
||||
Ok(vm.ctx.new_tuple(vec![cert, enc_type, usage]))
|
||||
@@ -1133,7 +1133,7 @@ fn cert_to_py(vm: &VirtualMachine, cert: &X509Ref, binary: bool) -> PyResult {
|
||||
dict.set_item("subjectAltName", vm.ctx.new_tuple(san), vm)?;
|
||||
};
|
||||
|
||||
dict.into_object()
|
||||
dict.into()
|
||||
};
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
);
|
||||
|
||||
let module = py_module!(vm, "unicodedata", {
|
||||
"UCD" => ucd_class.into_object(),
|
||||
"UCD" => ucd_class,
|
||||
"ucd_3_2_0" => ucd_3_2_0,
|
||||
// we do unidata_version here because the getter tries to do PyUCD::class() before
|
||||
// the module is in the VM
|
||||
|
||||
@@ -100,7 +100,7 @@ impl PyAsyncGen {
|
||||
aclose: true,
|
||||
state: AtomicCell::new(AwaitableState::Init),
|
||||
value: (
|
||||
vm.ctx.exceptions.generator_exit.clone().into_object(),
|
||||
vm.ctx.exceptions.generator_exit.clone().into(),
|
||||
vm.ctx.none(),
|
||||
vm.ctx.none(),
|
||||
),
|
||||
|
||||
@@ -184,9 +184,9 @@ impl SlotDescriptor for PyBuiltinMethod {
|
||||
Err(result) => return result,
|
||||
};
|
||||
if vm.is_none(&obj) && !Self::_cls_is(&cls, &obj.class()) {
|
||||
Ok(zelf.into_object())
|
||||
Ok(zelf.into())
|
||||
} else {
|
||||
Ok(vm.ctx.new_bound_method(zelf.into_object(), obj))
|
||||
Ok(vm.ctx.new_bound_method(zelf.into(), obj))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,7 +634,7 @@ impl PyByteArray {
|
||||
|
||||
#[pymethod]
|
||||
fn decode(zelf: PyRef<Self>, args: DecodeArgs, vm: &VirtualMachine) -> PyResult<PyStrRef> {
|
||||
bytes_decode(zelf.into_object(), args, vm)
|
||||
bytes_decode(zelf.into(), args, vm)
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
@@ -793,7 +793,7 @@ impl PyByteArrayIterator {
|
||||
fn reduce(&self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.internal
|
||||
.lock()
|
||||
.builtins_iter_reduce(|x| x.clone().into_object(), vm)
|
||||
.builtins_iter_reduce(|x| x.clone().into(), vm)
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
|
||||
@@ -480,7 +480,7 @@ impl PyBytes {
|
||||
/// currently, only 'utf-8' and 'ascii' emplemented
|
||||
#[pymethod]
|
||||
fn decode(zelf: PyRef<Self>, args: DecodeArgs, vm: &VirtualMachine) -> PyResult<PyStrRef> {
|
||||
bytes_decode(zelf.into_object(), args, vm)
|
||||
bytes_decode(zelf.into(), args, vm)
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
@@ -637,7 +637,7 @@ impl PyBytesIterator {
|
||||
fn reduce(&self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.internal
|
||||
.lock()
|
||||
.builtins_iter_reduce(|x| x.clone().into_object(), vm)
|
||||
.builtins_iter_reduce(|x| x.clone().into(), vm)
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
|
||||
@@ -50,7 +50,7 @@ impl SlotDescriptor for PyClassMethod {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
let (zelf, obj) = Self::_unwrap(zelf, obj, vm)?;
|
||||
let cls = cls.unwrap_or_else(|| obj.clone_class().into_object());
|
||||
let cls = cls.unwrap_or_else(|| obj.clone_class().into());
|
||||
Ok(vm.ctx.new_bound_method(zelf.callable.clone(), cls))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,14 +84,12 @@ impl ConstantBag for PyObjBag<'_> {
|
||||
bytecode::ConstantData::Float { value } => ctx.new_float(value),
|
||||
bytecode::ConstantData::Complex { value } => ctx.new_complex(value),
|
||||
bytecode::ConstantData::Str { value } if value.len() <= 20 => {
|
||||
vm.intern_string(value).into_object()
|
||||
vm.intern_string(value).into()
|
||||
}
|
||||
bytecode::ConstantData::Str { value } => vm.ctx.new_utf8_str(value),
|
||||
bytecode::ConstantData::Bytes { value } => ctx.new_bytes(value.to_vec()),
|
||||
bytecode::ConstantData::Boolean { value } => ctx.new_bool(value),
|
||||
bytecode::ConstantData::Code { code } => {
|
||||
ctx.new_code_object(code.map_bag(self)).into_object()
|
||||
}
|
||||
bytecode::ConstantData::Code { code } => ctx.new_code_object(code.map_bag(self)).into(),
|
||||
bytecode::ConstantData::Tuple { elements } => {
|
||||
let elements = elements
|
||||
.into_iter()
|
||||
@@ -112,13 +110,13 @@ impl ConstantBag for PyObjBag<'_> {
|
||||
bytecode::BorrowedConstant::Float { value } => ctx.new_float(value),
|
||||
bytecode::BorrowedConstant::Complex { value } => ctx.new_complex(value),
|
||||
bytecode::BorrowedConstant::Str { value } if value.len() <= 20 => {
|
||||
vm.intern_string(value).into_object()
|
||||
vm.intern_string(value).into()
|
||||
}
|
||||
bytecode::BorrowedConstant::Str { value } => vm.ctx.new_utf8_str(value),
|
||||
bytecode::BorrowedConstant::Bytes { value } => ctx.new_bytes(value.to_vec()),
|
||||
bytecode::BorrowedConstant::Boolean { value } => ctx.new_bool(value),
|
||||
bytecode::BorrowedConstant::Code { code } => {
|
||||
ctx.new_code_object(code.map_clone_bag(self)).into_object()
|
||||
ctx.new_code_object(code.map_clone_bag(self)).into()
|
||||
}
|
||||
bytecode::BorrowedConstant::Tuple { elements } => {
|
||||
let elements = elements
|
||||
@@ -256,7 +254,7 @@ impl PyRef<PyCode> {
|
||||
.code
|
||||
.varnames
|
||||
.iter()
|
||||
.map(|s| s.clone().into_object())
|
||||
.map(|s| s.clone().into())
|
||||
.collect();
|
||||
vm.ctx.new_tuple(varnames)
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ impl SlotConstructor for PyComplex {
|
||||
let val = if cls.is(&vm.ctx.types.complex_type) && imag_missing {
|
||||
match val.downcast_exact::<PyComplex>(vm) {
|
||||
Ok(c) => {
|
||||
return Ok(c.into_object());
|
||||
return Ok(c.into());
|
||||
}
|
||||
Err(val) => val,
|
||||
}
|
||||
|
||||
@@ -331,9 +331,9 @@ impl PyDict {
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn ior(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
fn ior(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
|
||||
PyDict::merge_object(&zelf.entries, other, vm)?;
|
||||
Ok(zelf.into_object())
|
||||
Ok(zelf)
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
@@ -482,7 +482,7 @@ impl PyDictRef {
|
||||
}
|
||||
|
||||
if !exact {
|
||||
if let Some(method_or_err) = vm.get_method(self.clone().into_object(), "__missing__") {
|
||||
if let Some(method_or_err) = vm.get_method(self.clone().into(), "__missing__") {
|
||||
let method = method_or_err?;
|
||||
return vm.invoke(&method, (key,)).map(Some);
|
||||
}
|
||||
@@ -495,7 +495,7 @@ impl PyDictRef {
|
||||
let mut attrs = PyAttributes::default();
|
||||
for (key, value) in self {
|
||||
let key: PyStrRef = key.downcast().expect("dict has non-string keys");
|
||||
attrs.insert(key.as_ref().to_owned(), value);
|
||||
attrs.insert(key.as_str().to_owned(), value);
|
||||
}
|
||||
attrs
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ impl SlotConstructor for PyFloat {
|
||||
OptionalArg::Present(val) => {
|
||||
let val = if cls.is(&vm.ctx.types.float_type) {
|
||||
match val.downcast_exact::<PyFloat>(vm) {
|
||||
Ok(f) => return Ok(f.into_object()),
|
||||
Ok(f) => return Ok(f.into()),
|
||||
Err(val) => val,
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -107,7 +107,7 @@ impl PyFunction {
|
||||
// Do we support `**kwargs` ?
|
||||
let kwargs = if code.flags.contains(bytecode::CodeFlags::HAS_VARKEYWORDS) {
|
||||
let d = vm.ctx.new_dict();
|
||||
fastlocals[vararg_offset] = Some(d.clone().into_object());
|
||||
fastlocals[vararg_offset] = Some(d.clone().into());
|
||||
Some(d)
|
||||
} else {
|
||||
None
|
||||
@@ -405,11 +405,12 @@ impl SlotDescriptor for PyFunction {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
let (zelf, obj) = Self::_unwrap(zelf, obj, vm)?;
|
||||
if vm.is_none(&obj) && !Self::_cls_is(&cls, &obj.class()) {
|
||||
Ok(zelf.into_object())
|
||||
let obj = if vm.is_none(&obj) && !Self::_cls_is(&cls, &obj.class()) {
|
||||
zelf.into()
|
||||
} else {
|
||||
Ok(vm.ctx.new_bound_method(zelf.into_object(), obj))
|
||||
}
|
||||
vm.ctx.new_bound_method(zelf.into(), obj)
|
||||
};
|
||||
Ok(obj)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,7 +454,7 @@ impl Comparable for PyBoundMethod {
|
||||
impl SlotGetattro for PyBoundMethod {
|
||||
fn getattro(zelf: PyRef<Self>, name: PyStrRef, vm: &VirtualMachine) -> PyResult {
|
||||
if let Some(obj) = zelf.get_class_attr(name.as_str()) {
|
||||
return vm.call_if_get_descriptor(obj, zelf.into_object());
|
||||
return vm.call_if_get_descriptor(obj, zelf.into());
|
||||
}
|
||||
vm.get_attribute(zelf.function.clone(), name)
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ pub fn get_jit_arg_types(func: &PyRef<PyFunction>, vm: &VirtualMachine) -> PyRes
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
let annotations = vm.get_attribute(func.clone().into_object(), "__annotations__")?;
|
||||
let annotations = vm.get_attribute(func.clone().into(), "__annotations__")?;
|
||||
if vm.is_none(&annotations) {
|
||||
Err(new_jit_error(
|
||||
"Jitting function requires arguments to have annotations".to_owned(),
|
||||
|
||||
@@ -120,7 +120,7 @@ impl PyList {
|
||||
if let Ok(new_elements) = vm.extract_elements(&other) {
|
||||
let mut e = new_elements;
|
||||
zelf.borrow_vec_mut().append(&mut e);
|
||||
zelf.into_object()
|
||||
zelf.into()
|
||||
} else {
|
||||
vm.ctx.not_implemented()
|
||||
}
|
||||
@@ -524,7 +524,7 @@ impl PyListIterator {
|
||||
fn reduce(&self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.internal
|
||||
.lock()
|
||||
.builtins_iter_reduce(|x| x.clone().into_object(), vm)
|
||||
.builtins_iter_reduce(|x| x.clone().into(), vm)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,7 +571,7 @@ impl PyListReverseIterator {
|
||||
fn reduce(&self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.internal
|
||||
.lock()
|
||||
.builtins_reversed_reduce(|x| x.clone().into_object(), vm)
|
||||
.builtins_reversed_reduce(|x| x.clone().into(), vm)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ impl PyMap {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self, vm: &VirtualMachine) -> PyResult<usize> {
|
||||
self.iterators.iter().try_fold(0, |prev, cur| {
|
||||
let cur = vm.length_hint(cur.as_object().clone())?.unwrap_or(0);
|
||||
let cur = vm.length_hint(cur.as_ref().clone())?.unwrap_or(0);
|
||||
let max = std::cmp::max(prev, cur);
|
||||
Ok(max)
|
||||
})
|
||||
|
||||
@@ -189,7 +189,7 @@ impl Iterable for PyMappingProxy {
|
||||
}
|
||||
};
|
||||
let iter = obj.get_iter(vm)?;
|
||||
Ok(iter.into_object())
|
||||
Ok(iter.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ impl PyMemoryView {
|
||||
if x.len() == 1 {
|
||||
x.fast_getitem(0)
|
||||
} else {
|
||||
x.into_object()
|
||||
x.into()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -838,7 +838,7 @@ fn format_unpack(
|
||||
if x.len() == 1 {
|
||||
x.fast_getitem(0)
|
||||
} else {
|
||||
x.into_object()
|
||||
x.into()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ impl PyModule {
|
||||
init_module_dict(
|
||||
vm,
|
||||
&zelf.as_object().dict().unwrap(),
|
||||
args.name.into_object(),
|
||||
args.name.into(),
|
||||
args.doc.into_pyobject(vm),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -240,8 +240,8 @@ impl PyBaseObject {
|
||||
fn init(_args: FuncArgs) {}
|
||||
|
||||
#[pyproperty(name = "__class__")]
|
||||
fn get_class(obj: PyObjectRef) -> PyObjectRef {
|
||||
obj.clone_class().into_object()
|
||||
fn get_class(obj: PyObjectRef) -> PyTypeRef {
|
||||
obj.clone_class()
|
||||
}
|
||||
|
||||
#[pyproperty(name = "__class__", setter)]
|
||||
@@ -285,7 +285,7 @@ impl PyBaseObject {
|
||||
fn reduce_ex(obj: PyObjectRef, proto: usize, vm: &VirtualMachine) -> PyResult {
|
||||
if let Some(reduce) = vm.get_attribute_opt(obj.clone(), "__reduce__")? {
|
||||
let object_reduce = vm.ctx.types.object_type.get_attr("__reduce__").unwrap();
|
||||
let class_reduce = vm.get_attribute(obj.clone_class().into_object(), "__reduce__")?;
|
||||
let class_reduce = vm.get_attribute(obj.clone_class().into(), "__reduce__")?;
|
||||
if !class_reduce.is(&object_reduce) {
|
||||
return vm.invoke(&reduce, ());
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ impl SlotDescriptor for PyProperty {
|
||||
) -> PyResult {
|
||||
let (zelf, obj) = Self::_unwrap(zelf, obj, vm)?;
|
||||
if vm.is_none(&obj) {
|
||||
Ok(zelf.into_object())
|
||||
Ok(zelf.into())
|
||||
} else if let Some(getter) = zelf.getter.read().as_ref() {
|
||||
vm.invoke(getter, (obj,))
|
||||
} else {
|
||||
|
||||
@@ -200,7 +200,7 @@ impl PyStrIterator {
|
||||
self.internal
|
||||
.lock()
|
||||
.0
|
||||
.builtins_iter_reduce(|x| x.clone().into_object(), vm)
|
||||
.builtins_iter_reduce(|x| x.clone().into(), vm)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ impl SlotConstructor for PyStr {
|
||||
}
|
||||
};
|
||||
if string.class().is(&cls) {
|
||||
Ok(string.into_object())
|
||||
Ok(string.into())
|
||||
} else {
|
||||
PyStr::from(string.as_str()).into_pyresult_with_type(vm, cls)
|
||||
}
|
||||
@@ -949,16 +949,16 @@ impl PyStr {
|
||||
|| self.as_str().splitn(2, sep.as_str()),
|
||||
vm,
|
||||
)?;
|
||||
Ok((
|
||||
let partition = (
|
||||
self.new_substr(front),
|
||||
if has_mid {
|
||||
sep.into_object()
|
||||
sep.into()
|
||||
} else {
|
||||
vm.ctx.new_ascii_literal(ascii!(""))
|
||||
},
|
||||
self.new_substr(back),
|
||||
)
|
||||
.into_pyobject(vm))
|
||||
);
|
||||
Ok(partition.into_pyobject(vm))
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -971,7 +971,7 @@ impl PyStr {
|
||||
Ok((
|
||||
self.new_substr(front),
|
||||
if has_mid {
|
||||
sep.into_object()
|
||||
sep.into()
|
||||
} else {
|
||||
vm.ctx.new_ascii_literal(ascii!(""))
|
||||
},
|
||||
@@ -1520,7 +1520,7 @@ mod tests {
|
||||
.set_item("c", vm.ctx.new_ascii_literal(ascii!("xda")), &vm)
|
||||
.unwrap();
|
||||
let translated = PyStr::maketrans(
|
||||
table.into_object(),
|
||||
table.into(),
|
||||
OptionalArg::Missing,
|
||||
OptionalArg::Missing,
|
||||
&vm,
|
||||
|
||||
@@ -119,7 +119,7 @@ impl PySuper {
|
||||
|
||||
impl SlotGetattro for PySuper {
|
||||
fn getattro(zelf: PyRef<Self>, name: PyStrRef, vm: &VirtualMachine) -> PyResult {
|
||||
let skip = |zelf: PyRef<Self>, name| vm.generic_getattribute(zelf.into_object(), name);
|
||||
let skip = |zelf: PyRef<Self>, name| vm.generic_getattribute(zelf.into(), name);
|
||||
let (obj, start_type): (PyObjectRef, PyTypeRef) = match zelf.obj.clone() {
|
||||
Some(o) => o,
|
||||
None => return skip(zelf, name),
|
||||
@@ -162,13 +162,11 @@ impl SlotDescriptor for PySuper {
|
||||
) -> PyResult {
|
||||
let (zelf, obj) = Self::_unwrap(zelf, obj, vm)?;
|
||||
if vm.is_none(&obj) || zelf.obj.is_some() {
|
||||
return Ok(zelf.into_object());
|
||||
return Ok(zelf.into());
|
||||
}
|
||||
let zelf_class = zelf.as_object().class();
|
||||
if zelf_class.is(&vm.ctx.types.super_type) {
|
||||
Ok(PySuper::new(zelf.typ.clone(), obj, vm)?
|
||||
.into_ref(vm)
|
||||
.into_object())
|
||||
Ok(PySuper::new(zelf.typ.clone(), obj, vm)?.into_object(vm))
|
||||
} else {
|
||||
let obj = vm.unwrap_or_none(zelf.obj.clone().map(|(o, _)| o));
|
||||
vm.invoke(
|
||||
|
||||
+13
-20
@@ -187,7 +187,7 @@ impl PyType {
|
||||
let new = vm
|
||||
.get_attribute_opt(cls.as_object().clone(), "__new__")?
|
||||
.unwrap();
|
||||
args.prepend_arg(cls.into_object());
|
||||
args.prepend_arg(cls.into());
|
||||
vm.invoke(&new, args)
|
||||
};
|
||||
update_slot!(new, func);
|
||||
@@ -493,11 +493,8 @@ impl PyType {
|
||||
|
||||
#[pymethod]
|
||||
fn mro(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.ctx.new_list(
|
||||
zelf.iter_mro()
|
||||
.map(|cls| cls.clone().into_object())
|
||||
.collect(),
|
||||
)
|
||||
vm.ctx
|
||||
.new_list(zelf.iter_mro().map(|cls| cls.clone().into()).collect())
|
||||
}
|
||||
#[pyslot]
|
||||
fn slot_new(metatype: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
@@ -505,7 +502,7 @@ impl PyType {
|
||||
|
||||
let is_type_type = metatype.is(&vm.ctx.types.type_type);
|
||||
if is_type_type && args.args.len() == 1 && args.kwargs.is_empty() {
|
||||
return Ok(args.args[0].clone_class().into_object());
|
||||
return Ok(args.args[0].clone_class().into());
|
||||
}
|
||||
|
||||
if args.args.len() != 3 {
|
||||
@@ -632,16 +629,12 @@ impl PyType {
|
||||
|
||||
if let Some(initter) = typ.get_super_attr("__init_subclass__") {
|
||||
let initter = vm
|
||||
.call_get_descriptor_specific(
|
||||
initter.clone(),
|
||||
None,
|
||||
Some(typ.clone().into_object()),
|
||||
)
|
||||
.call_get_descriptor_specific(initter.clone(), None, Some(typ.clone().into()))
|
||||
.unwrap_or(Ok(initter))?;
|
||||
vm.invoke(&initter, kwargs)?;
|
||||
};
|
||||
|
||||
Ok(typ.into_object())
|
||||
Ok(typ.into())
|
||||
}
|
||||
|
||||
#[pyproperty(magic)]
|
||||
@@ -703,8 +696,8 @@ impl SlotGetattro for PyType {
|
||||
.is_some()
|
||||
{
|
||||
if let Some(descr_get) = attr_class.mro_find_map(|cls| cls.slots.descr_get.load()) {
|
||||
let mcl = PyLease::into_pyref(mcl).into_object();
|
||||
return descr_get(attr.clone(), Some(zelf.into_object()), Some(mcl), vm);
|
||||
let mcl = PyLease::into_pyref(mcl).into();
|
||||
return descr_get(attr.clone(), Some(zelf.into()), Some(mcl), vm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -714,7 +707,7 @@ impl SlotGetattro for PyType {
|
||||
if let Some(ref attr) = zelf_attr {
|
||||
if let Some(descr_get) = attr.class().mro_find_map(|cls| cls.slots.descr_get.load()) {
|
||||
drop(mcl);
|
||||
return descr_get(attr.clone(), None, Some(zelf.into_object()), vm);
|
||||
return descr_get(attr.clone(), None, Some(zelf.into()), vm);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,7 +715,7 @@ impl SlotGetattro for PyType {
|
||||
Ok(cls_attr)
|
||||
} else if let Some(attr) = mcl_attr {
|
||||
drop(mcl);
|
||||
vm.call_if_get_descriptor(attr, zelf.into_object())
|
||||
vm.call_if_get_descriptor(attr, zelf.into())
|
||||
} else {
|
||||
Err(vm.new_attribute_error(format!(
|
||||
"type object '{}' has no attribute '{}'",
|
||||
@@ -743,7 +736,7 @@ impl SlotSetattro for PyType {
|
||||
if let Some(attr) = zelf.get_class_attr(attr_name.as_str()) {
|
||||
let descr_set = attr.class().mro_find_map(|cls| cls.slots.descr_set.load());
|
||||
if let Some(descriptor) = descr_set {
|
||||
return descriptor(attr, zelf.clone().into_object(), value, vm);
|
||||
return descriptor(attr, zelf.clone().into(), value, vm);
|
||||
}
|
||||
}
|
||||
let assign = value.is_some();
|
||||
@@ -756,7 +749,7 @@ impl SlotSetattro for PyType {
|
||||
if prev_value.is_none() {
|
||||
return Err(vm.new_exception(
|
||||
vm.ctx.exceptions.attribute_error.clone(),
|
||||
vec![attr_name.into_object()],
|
||||
vec![attr_name.into()],
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -810,7 +803,7 @@ fn subtype_get_dict(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
cls.name()
|
||||
)))
|
||||
})?,
|
||||
None => object::object_get_dict(obj, vm)?.into_object(),
|
||||
None => object::object_get_dict(obj, vm)?.into(),
|
||||
};
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ impl PyRange {
|
||||
step: substep.into_pyref(vm),
|
||||
}
|
||||
.into_ref(vm)
|
||||
.into_object())
|
||||
.into())
|
||||
}
|
||||
RangeIndex::Int(index) => match self.get(index.as_bigint()) {
|
||||
Some(value) => Ok(vm.ctx.new_int(value)),
|
||||
@@ -371,7 +371,7 @@ impl PyRange {
|
||||
PyRange::new_from(cls, start, stop, step, vm)
|
||||
}?;
|
||||
|
||||
Ok(range.into_object())
|
||||
Ok(range.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,16 +411,12 @@ impl Hashable for PyRange {
|
||||
let elements = if length.is_zero() {
|
||||
[vm.ctx.new_int(length), vm.ctx.none(), vm.ctx.none()]
|
||||
} else if length.is_one() {
|
||||
[
|
||||
vm.ctx.new_int(length),
|
||||
zelf.start().into_object(),
|
||||
vm.ctx.none(),
|
||||
]
|
||||
[vm.ctx.new_int(length), zelf.start().into(), vm.ctx.none()]
|
||||
} else {
|
||||
[
|
||||
vm.ctx.new_int(length),
|
||||
zelf.start().into_object(),
|
||||
zelf.step().into_object(),
|
||||
zelf.start().into(),
|
||||
zelf.step().into(),
|
||||
]
|
||||
};
|
||||
crate::utils::hash_iter(elements.iter(), vm)
|
||||
|
||||
@@ -609,7 +609,7 @@ impl PySet {
|
||||
zelf: PyRef<Self>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<(PyTypeRef, PyObjectRef, Option<PyDictRef>)> {
|
||||
reduce_set(&zelf.into_object(), vm)
|
||||
reduce_set(&zelf.into(), vm)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,7 +651,7 @@ impl SlotConstructor for PyFrozenSet {
|
||||
let elements = if let OptionalArg::Present(iterable) = iterable {
|
||||
let iterable = if cls.is(&vm.ctx.types.frozenset_type) {
|
||||
match iterable.downcast_exact::<Self>(vm) {
|
||||
Ok(fs) => return Ok(fs.into_object()),
|
||||
Ok(fs) => return Ok(fs.into()),
|
||||
Err(iterable) => iterable,
|
||||
}
|
||||
} else {
|
||||
@@ -664,7 +664,7 @@ impl SlotConstructor for PyFrozenSet {
|
||||
|
||||
// Return empty fs if iterable passed is empty and only for exact fs types.
|
||||
if elements.is_empty() && cls.is(&vm.ctx.types.frozenset_type) {
|
||||
Ok(vm.ctx.empty_frozenset.clone().into_object())
|
||||
Ok(vm.ctx.empty_frozenset.clone().into())
|
||||
} else {
|
||||
Self::from_iter(vm, elements).and_then(|o| o.into_pyresult_with_type(vm, cls))
|
||||
}
|
||||
@@ -798,7 +798,7 @@ impl PyFrozenSet {
|
||||
zelf: PyRef<Self>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<(PyTypeRef, PyObjectRef, Option<PyDictRef>)> {
|
||||
reduce_set(&zelf.into_object(), vm)
|
||||
reduce_set(&zelf.into(), vm)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ impl SlotConstructor for PyNone {
|
||||
type Args = ();
|
||||
|
||||
fn py_new(_: PyTypeRef, _args: Self::Args, vm: &VirtualMachine) -> PyResult {
|
||||
Ok(vm.ctx.none.clone().into_object())
|
||||
Ok(vm.ctx.none.clone().into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ impl SlotConstructor for PyNotImplemented {
|
||||
type Args = ();
|
||||
|
||||
fn py_new(_: PyTypeRef, _args: Self::Args, vm: &VirtualMachine) -> PyResult {
|
||||
Ok(vm.ctx.not_implemented.clone().into_object())
|
||||
Ok(vm.ctx.not_implemented.clone().into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ impl SlotConstructor for PyEllipsis {
|
||||
type Args = ();
|
||||
|
||||
fn py_new(_cls: PyTypeRef, _args: Self::Args, vm: &VirtualMachine) -> PyResult {
|
||||
Ok(vm.ctx.ellipsis.clone().into_object())
|
||||
Ok(vm.ctx.ellipsis.clone().into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ impl SlotConstructor for PyTuple {
|
||||
let elements = if let OptionalArg::Present(iterable) = iterable {
|
||||
let iterable = if cls.is(&vm.ctx.types.tuple_type) {
|
||||
match iterable.downcast_exact::<Self>(vm) {
|
||||
Ok(tuple) => return Ok(tuple.into_object()),
|
||||
Ok(tuple) => return Ok(tuple.into()),
|
||||
Err(iterable) => iterable,
|
||||
}
|
||||
} else {
|
||||
@@ -97,7 +97,7 @@ impl SlotConstructor for PyTuple {
|
||||
};
|
||||
// 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().into_object())
|
||||
Ok(vm.ctx.empty_tuple.clone().into())
|
||||
} else {
|
||||
Self {
|
||||
elements: elements.into_boxed_slice(),
|
||||
@@ -375,7 +375,7 @@ impl PyTupleIterator {
|
||||
fn reduce(&self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.internal
|
||||
.lock()
|
||||
.builtins_iter_reduce(|x| x.clone().into_object(), vm)
|
||||
.builtins_iter_reduce(|x| x.clone().into(), vm)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,6 +458,6 @@ impl<T: TransmuteFromObject> From<PyTupleTyped<T>> for PyTupleRef {
|
||||
impl<T: TransmuteFromObject> IntoPyObject for PyTupleTyped<T> {
|
||||
#[inline]
|
||||
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.tuple.into_object()
|
||||
self.tuple.into()
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ impl PyZip {
|
||||
let iterators = zelf
|
||||
.iterators
|
||||
.iter()
|
||||
.map(|obj| obj.clone().into_object())
|
||||
.map(|obj| obj.clone().into())
|
||||
.collect::<Vec<_>>();
|
||||
let tuple_iter = vm.ctx.new_tuple(iterators);
|
||||
Ok(if zelf.strict.load(atomic::Ordering::Acquire) {
|
||||
|
||||
+7
-7
@@ -51,7 +51,7 @@ impl PyCodec {
|
||||
}
|
||||
|
||||
pub fn is_text_codec(&self, vm: &VirtualMachine) -> PyResult<bool> {
|
||||
let is_text = vm.get_attribute_opt(self.0.clone().into_object(), "_is_text_encoding")?;
|
||||
let is_text = vm.get_attribute_opt(self.0.clone().into(), "_is_text_encoding")?;
|
||||
is_text.map_or(Ok(true), |is_text| is_text.try_to_bool(vm))
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ impl PyCodec {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
let args = match errors {
|
||||
Some(errors) => vec![obj, errors.into_object()],
|
||||
Some(errors) => vec![obj, errors.into()],
|
||||
None => vec![obj],
|
||||
};
|
||||
let res = vm.invoke(self.get_encode_func(), args)?;
|
||||
@@ -84,7 +84,7 @@ impl PyCodec {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
let args = match errors {
|
||||
Some(errors) => vec![obj, errors.into_object()],
|
||||
Some(errors) => vec![obj, errors.into()],
|
||||
None => vec![obj],
|
||||
};
|
||||
let res = vm.invoke(self.get_decode_func(), args)?;
|
||||
@@ -105,7 +105,7 @@ impl PyCodec {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
let args = match errors {
|
||||
Some(e) => vec![e.into_object()],
|
||||
Some(e) => vec![e.into()],
|
||||
None => vec![],
|
||||
};
|
||||
vm.call_method(self.0.as_object(), "incrementalencoder", args)
|
||||
@@ -117,7 +117,7 @@ impl PyCodec {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
let args = match errors {
|
||||
Some(e) => vec![e.into_object()],
|
||||
Some(e) => vec![e.into()],
|
||||
None => vec![],
|
||||
};
|
||||
vm.call_method(self.0.as_object(), "incrementaldecoder", args)
|
||||
@@ -138,7 +138,7 @@ impl TryFromObject for PyCodec {
|
||||
impl IntoPyObject for PyCodec {
|
||||
#[inline]
|
||||
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.0.into_object()
|
||||
self.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ impl CodecsRegistry {
|
||||
) -> PyResult<PyBytesRef> {
|
||||
let codec = self._lookup_text_encoding(encoding, "codecs.encode()", vm)?;
|
||||
codec
|
||||
.encode(obj.into_object(), errors, vm)?
|
||||
.encode(obj.into(), errors, vm)?
|
||||
.downcast()
|
||||
.map_err(|obj| {
|
||||
vm.new_type_error(format!(
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ impl Coro {
|
||||
let result = self.run_with_context(gen, vm, |f| {
|
||||
f.gen_throw(
|
||||
vm,
|
||||
vm.ctx.exceptions.generator_exit.clone().into_object(),
|
||||
vm.ctx.exceptions.generator_exit.clone().into(),
|
||||
vm.ctx.none(),
|
||||
vm.ctx.none(),
|
||||
)
|
||||
|
||||
@@ -229,7 +229,7 @@ impl TryFromObject for ExceptionCtor {
|
||||
if cls.issubclass(&vm.ctx.exceptions.base_exception_type) {
|
||||
Ok(Self::Class(cls))
|
||||
} else {
|
||||
Err(cls.into_object())
|
||||
Err(cls.into())
|
||||
}
|
||||
})
|
||||
.or_else(|obj| obj.downcast::<PyBaseException>().map(Self::Instance))
|
||||
@@ -295,7 +295,7 @@ pub fn split(
|
||||
vm: &VirtualMachine,
|
||||
) -> (PyObjectRef, PyObjectRef, PyObjectRef) {
|
||||
let tb = exc.traceback().into_pyobject(vm);
|
||||
(exc.clone_class().into_object(), exc.into_object(), tb)
|
||||
(exc.clone_class().into(), exc.into(), tb)
|
||||
}
|
||||
|
||||
/// Similar to PyErr_NormalizeException in CPython
|
||||
@@ -1082,7 +1082,7 @@ pub(super) mod types {
|
||||
args: FuncArgs,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
let exc_self = zelf.into_object();
|
||||
let exc_self = zelf.into();
|
||||
vm.set_attr(
|
||||
&exc_self,
|
||||
"name",
|
||||
|
||||
+2
-2
@@ -892,8 +892,8 @@ fn call_object_format(
|
||||
format_spec: &str,
|
||||
) -> PyResult<PyStrRef> {
|
||||
let argument = match preconversion_spec.and_then(FormatPreconversor::from_char) {
|
||||
Some(FormatPreconversor::Str) => vm.to_str(&argument)?.into_object(),
|
||||
Some(FormatPreconversor::Repr) => vm.to_repr(&argument)?.into_object(),
|
||||
Some(FormatPreconversor::Str) => vm.to_str(&argument)?.into(),
|
||||
Some(FormatPreconversor::Repr) => vm.to_repr(&argument)?.into(),
|
||||
Some(FormatPreconversor::Ascii) => vm.ctx.new_utf8_str(builtins::ascii(argument, vm)?),
|
||||
Some(FormatPreconversor::Bytes) => vm.call_method(&argument, "decode", ())?,
|
||||
None => argument,
|
||||
|
||||
+12
-12
@@ -588,7 +588,7 @@ impl ExecutingFrame<'_> {
|
||||
}
|
||||
bytecode::Instruction::LoadClosure(i) => {
|
||||
let value = self.cells_frees[*i as usize].clone();
|
||||
self.push_value(value.into_object());
|
||||
self.push_value(value.into());
|
||||
Ok(None)
|
||||
}
|
||||
bytecode::Instruction::Subscript => self.execute_subscript(vm),
|
||||
@@ -638,7 +638,7 @@ impl ExecutingFrame<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
self.push_value(set.into_object());
|
||||
self.push_value(set.into());
|
||||
Ok(None)
|
||||
}
|
||||
bytecode::Instruction::BuildTuple { size, unpack } => {
|
||||
@@ -706,7 +706,7 @@ impl ExecutingFrame<'_> {
|
||||
bytecode::Instruction::SetupAnnotation => {
|
||||
if !self.locals.contains_key("__annotations__", vm) {
|
||||
self.locals
|
||||
.set_item("__annotations__", vm.ctx.new_dict().into_object(), vm)?;
|
||||
.set_item("__annotations__", vm.ctx.new_dict().into(), vm)?;
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
@@ -823,7 +823,7 @@ impl ExecutingFrame<'_> {
|
||||
bytecode::Instruction::GetIter => {
|
||||
let iterated_obj = self.pop_value();
|
||||
let iter_obj = iterated_obj.get_iter(vm)?;
|
||||
self.push_value(iter_obj.into_object());
|
||||
self.push_value(iter_obj.into());
|
||||
Ok(None)
|
||||
}
|
||||
bytecode::Instruction::GetAwaitable => {
|
||||
@@ -1014,8 +1014,8 @@ impl ExecutingFrame<'_> {
|
||||
use bytecode::ConversionFlag;
|
||||
let value = self.pop_value();
|
||||
let value = match conversion {
|
||||
ConversionFlag::Str => vm.to_str(&value)?.into_object(),
|
||||
ConversionFlag::Repr => vm.to_repr(&value)?.into_object(),
|
||||
ConversionFlag::Str => vm.to_str(&value)?.into(),
|
||||
ConversionFlag::Repr => vm.to_repr(&value)?.into(),
|
||||
ConversionFlag::Ascii => vm.ctx.new_utf8_str(builtins::ascii(value, vm)?),
|
||||
ConversionFlag::None => value,
|
||||
};
|
||||
@@ -1110,7 +1110,7 @@ impl ExecutingFrame<'_> {
|
||||
let all: Vec<PyStrRef> = vm.extract_elements(&all)?;
|
||||
let all: Vec<String> = all
|
||||
.into_iter()
|
||||
.map(|name| name.as_ref().to_owned())
|
||||
.map(|name| name.as_str().to_owned())
|
||||
.collect();
|
||||
Box::new(move |name| all.contains(&name.to_owned()))
|
||||
} else {
|
||||
@@ -1170,7 +1170,7 @@ impl ExecutingFrame<'_> {
|
||||
});
|
||||
vm.contextualize_exception(&exception);
|
||||
vm.set_exception(Some(exception.clone()));
|
||||
self.push_value(exception.into_object());
|
||||
self.push_value(exception.into());
|
||||
self.jump(handler);
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -1275,7 +1275,7 @@ impl ExecutingFrame<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
self.push_value(map_obj.into_object());
|
||||
self.push_value(map_obj.into());
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
@@ -1290,7 +1290,7 @@ impl ExecutingFrame<'_> {
|
||||
step,
|
||||
}
|
||||
.into_ref(vm);
|
||||
self.push_value(obj.into_object());
|
||||
self.push_value(obj.into());
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
@@ -1528,7 +1528,7 @@ impl ExecutingFrame<'_> {
|
||||
let annotations = if flags.contains(bytecode::MakeFunctionFlags::ANNOTATIONS) {
|
||||
self.pop_value()
|
||||
} else {
|
||||
vm.ctx.new_dict().into_object()
|
||||
vm.ctx.new_dict().into()
|
||||
};
|
||||
|
||||
let kw_only_defaults = if flags.contains(bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS) {
|
||||
@@ -1718,7 +1718,7 @@ impl ExecutingFrame<'_> {
|
||||
}
|
||||
|
||||
fn delete_attr(&mut self, vm: &VirtualMachine, attr: bytecode::NameIdx) -> FrameResult {
|
||||
let attr_name = self.code.names[attr as usize].clone().into_object();
|
||||
let attr_name = self.code.names[attr as usize].clone();
|
||||
let parent = self.pop_value();
|
||||
vm.del_attr(&parent, attr_name)?;
|
||||
Ok(None)
|
||||
|
||||
+1
-1
@@ -435,7 +435,7 @@ impl<T> AsRef<[T]> for PosArgs<T> {
|
||||
impl<T: PyValue> PosArgs<PyRef<T>> {
|
||||
pub fn into_tuple(self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.ctx
|
||||
.new_tuple(self.0.into_iter().map(PyRef::into_object).collect())
|
||||
.new_tuple(self.0.into_iter().map(Into::into).collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::IntoFuncArgs;
|
||||
use crate::{
|
||||
builtins::iter::PySequenceIterator, protocol::PyIter, protocol::PyIterIter, PyObjectRef,
|
||||
PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
PyObjectWrap, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
@@ -15,9 +15,16 @@ impl ArgCallable {
|
||||
pub fn invoke(&self, args: impl IntoFuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
vm.invoke(&self.obj, args)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_object(self) -> PyObjectRef {
|
||||
impl AsRef<PyObjectRef> for ArgCallable {
|
||||
fn as_ref(&self) -> &PyObjectRef {
|
||||
&self.obj
|
||||
}
|
||||
}
|
||||
|
||||
impl PyObjectWrap for ArgCallable {
|
||||
fn into_object(self) -> PyObjectRef {
|
||||
self.obj
|
||||
}
|
||||
}
|
||||
|
||||
+7
-9
@@ -77,15 +77,14 @@ macro_rules! py_namespace {
|
||||
/// use num_traits::Zero;
|
||||
///
|
||||
/// use rustpython_vm::match_class;
|
||||
/// use rustpython_vm::builtins::PyFloat;
|
||||
/// use rustpython_vm::builtins::PyInt;
|
||||
/// use rustpython_vm::PyValue;
|
||||
/// use rustpython_vm::builtins::{PyFloat, PyInt};
|
||||
/// use rustpython_vm::{PyValue};
|
||||
///
|
||||
/// # rustpython_vm::Interpreter::default().enter(|vm| {
|
||||
/// let obj = PyInt::from(0).into_ref(&vm).into_object();
|
||||
/// let obj = PyInt::from(0).into_object(vm);
|
||||
/// assert_eq!(
|
||||
/// "int",
|
||||
/// match_class!(match obj.clone() {
|
||||
/// match_class!(match obj {
|
||||
/// PyInt => "int",
|
||||
/// PyFloat => "float",
|
||||
/// _ => "neither",
|
||||
@@ -102,12 +101,11 @@ macro_rules! py_namespace {
|
||||
/// use num_traits::Zero;
|
||||
///
|
||||
/// use rustpython_vm::match_class;
|
||||
/// use rustpython_vm::builtins::PyFloat;
|
||||
/// use rustpython_vm::builtins::PyInt;
|
||||
/// use rustpython_vm::PyValue;
|
||||
/// use rustpython_vm::builtins::{PyFloat, PyInt};
|
||||
/// use rustpython_vm::{ PyValue};
|
||||
///
|
||||
/// # rustpython_vm::Interpreter::default().enter(|vm| {
|
||||
/// let obj = PyInt::from(0).into_ref(vm).into_object();
|
||||
/// let obj = PyInt::from(0).into_object(vm);
|
||||
///
|
||||
/// let int_value = match_class!(match obj {
|
||||
/// i @ PyInt => i.as_bigint().clone(),
|
||||
|
||||
+12
-16
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
builtins::iter::PySequenceIterator,
|
||||
function::{IntoPyObject, IntoPyResult},
|
||||
PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
PyObjectRef, PyObjectWrap, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
};
|
||||
use std::borrow::Borrow;
|
||||
use std::ops::Deref;
|
||||
@@ -15,9 +15,6 @@ where
|
||||
O: Borrow<PyObjectRef>;
|
||||
|
||||
impl PyIter<PyObjectRef> {
|
||||
pub fn into_object(self) -> PyObjectRef {
|
||||
self.0
|
||||
}
|
||||
pub fn check(obj: &PyObjectRef) -> bool {
|
||||
obj.class()
|
||||
.mro_find_map(|x| x.slots.iternext.load())
|
||||
@@ -32,9 +29,6 @@ where
|
||||
pub fn new(obj: O) -> Self {
|
||||
Self(obj)
|
||||
}
|
||||
pub fn as_object(&self) -> &PyObjectRef {
|
||||
self.0.borrow()
|
||||
}
|
||||
pub fn next(&self, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
|
||||
let iternext = {
|
||||
self.0
|
||||
@@ -55,7 +49,7 @@ where
|
||||
&'b self,
|
||||
vm: &'a VirtualMachine,
|
||||
) -> PyResult<PyIterIter<'a, U, &'b PyObjectRef>> {
|
||||
let length_hint = vm.length_hint(self.as_object().clone())?;
|
||||
let length_hint = vm.length_hint(self.as_ref().clone())?;
|
||||
Ok(PyIterIter::new(vm, self.0.borrow(), length_hint))
|
||||
}
|
||||
|
||||
@@ -75,11 +69,17 @@ impl PyIter<PyObjectRef> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<O> Borrow<PyObjectRef> for PyIter<O>
|
||||
impl PyObjectWrap for PyIter<PyObjectRef> {
|
||||
fn into_object(self) -> PyObjectRef {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<O> AsRef<PyObjectRef> for PyIter<O>
|
||||
where
|
||||
O: Borrow<PyObjectRef>,
|
||||
{
|
||||
fn borrow(&self) -> &PyObjectRef {
|
||||
fn as_ref(&self) -> &PyObjectRef {
|
||||
self.0.borrow()
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ where
|
||||
|
||||
impl IntoPyObject for PyIter<PyObjectRef> {
|
||||
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.into_object()
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,11 +124,7 @@ impl TryFromObject for PyIter<PyObjectRef> {
|
||||
vm.get_method_or_type_error(iter_target.clone(), "__getitem__", || {
|
||||
format!("'{}' object is not iterable", iter_target.class().name())
|
||||
})?;
|
||||
Ok(Self(
|
||||
PySequenceIterator::new(iter_target)
|
||||
.into_ref(vm)
|
||||
.into_object(),
|
||||
))
|
||||
Ok(Self(PySequenceIterator::new(iter_target).into_object(vm)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ use crate::{
|
||||
PyDictRef, PyList,
|
||||
},
|
||||
function::IntoPyObject,
|
||||
IdProtocol, PyObjectRef, PyResult, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
IdProtocol, PyObjectRef, PyObjectWrap, PyResult, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
};
|
||||
use std::borrow::Borrow;
|
||||
use std::ops::Deref;
|
||||
|
||||
// Mapping protocol
|
||||
// https://docs.python.org/3/c-api/mapping.html
|
||||
@@ -27,10 +26,6 @@ where
|
||||
T: Borrow<PyObjectRef>;
|
||||
|
||||
impl PyMapping<PyObjectRef> {
|
||||
pub fn into_object(self) -> PyObjectRef {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn check(obj: &PyObjectRef) -> bool {
|
||||
obj.class()
|
||||
.mro_find_map(|x| x.slots.as_mapping.load())
|
||||
@@ -101,28 +96,24 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Borrow<PyObjectRef> for PyMapping<T>
|
||||
where
|
||||
T: Borrow<PyObjectRef>,
|
||||
{
|
||||
fn borrow(&self) -> &PyObjectRef {
|
||||
self.0.borrow()
|
||||
impl PyObjectWrap for PyMapping<PyObjectRef> {
|
||||
fn into_object(self) -> PyObjectRef {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for PyMapping<T>
|
||||
impl<O> AsRef<PyObjectRef> for PyMapping<O>
|
||||
where
|
||||
T: Borrow<PyObjectRef>,
|
||||
O: Borrow<PyObjectRef>,
|
||||
{
|
||||
type Target = PyObjectRef;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
fn as_ref(&self) -> &PyObjectRef {
|
||||
self.0.borrow()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoPyObject for PyMapping<PyObjectRef> {
|
||||
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.into_object()
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -77,7 +77,7 @@ pub fn file_readline(obj: &PyObjectRef, size: Option<usize>, vm: &VirtualMachine
|
||||
if let Some(nonl) = sval.strip_suffix('\n') {
|
||||
vm.ctx.new_utf8_str(nonl)
|
||||
} else {
|
||||
s.into_object()
|
||||
s.into()
|
||||
}
|
||||
}
|
||||
b @ PyBytes => {
|
||||
@@ -88,7 +88,7 @@ pub fn file_readline(obj: &PyObjectRef, size: Option<usize>, vm: &VirtualMachine
|
||||
if buf.last() == Some(&b'\n') {
|
||||
vm.ctx.new_bytes(buf[..buf.len() - 1].to_owned())
|
||||
} else {
|
||||
b.into_object()
|
||||
b.into()
|
||||
}
|
||||
}
|
||||
_ => return Err(vm.new_type_error("object.readline() returned non-string".to_owned())),
|
||||
|
||||
+1
-1
@@ -208,6 +208,6 @@ impl<'de> Visitor<'de> for PyObjectDeserializer<'de> {
|
||||
while let Some((key_obj, value)) = access.next_entry_seed(self.clone(), self.clone())? {
|
||||
dict.set_item(key_obj, value, self.vm).unwrap();
|
||||
}
|
||||
Ok(dict.into_object())
|
||||
Ok(dict.into())
|
||||
}
|
||||
}
|
||||
+15
-28
@@ -3,7 +3,7 @@ use crate::common::{
|
||||
rc::PyRc,
|
||||
static_cell,
|
||||
};
|
||||
pub use crate::pyobjectrc::{PyObject, PyObjectRef, PyObjectWeak, PyRef, PyWeakRef};
|
||||
pub use crate::pyobjectrc::{PyObject, PyObjectRef, PyObjectWeak, PyObjectWrap, PyRef, PyWeakRef};
|
||||
use crate::{
|
||||
builtins::{
|
||||
builtinfunc::PyNativeFuncDef,
|
||||
@@ -120,7 +120,7 @@ impl PyContext {
|
||||
PyNativeFuncDef::new(PyType::__new__.into_func(), new_str).into_function(),
|
||||
&types.builtin_function_or_method_type,
|
||||
)
|
||||
.into_object();
|
||||
.into();
|
||||
|
||||
let context = PyContext {
|
||||
true_value,
|
||||
@@ -149,15 +149,15 @@ impl PyContext {
|
||||
}
|
||||
|
||||
pub fn none(&self) -> PyObjectRef {
|
||||
self.none.clone().into_object()
|
||||
self.none.clone().into()
|
||||
}
|
||||
|
||||
pub fn ellipsis(&self) -> PyObjectRef {
|
||||
self.ellipsis.clone().into_object()
|
||||
self.ellipsis.clone().into()
|
||||
}
|
||||
|
||||
pub fn not_implemented(&self) -> PyObjectRef {
|
||||
self.not_implemented.clone().into_object()
|
||||
self.not_implemented.clone().into()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -235,11 +235,11 @@ impl PyContext {
|
||||
} else {
|
||||
&self.false_value
|
||||
};
|
||||
value.clone().into_object()
|
||||
value.clone().into()
|
||||
}
|
||||
|
||||
pub fn new_tuple(&self, elements: Vec<PyObjectRef>) -> PyObjectRef {
|
||||
PyTupleRef::with_elements(elements, self).into_object()
|
||||
PyTupleRef::with_elements(elements, self).into()
|
||||
}
|
||||
|
||||
pub fn new_list(&self, elements: Vec<PyObjectRef>) -> PyObjectRef {
|
||||
@@ -449,18 +449,6 @@ pub(crate) fn pyref_type_error(
|
||||
))
|
||||
}
|
||||
|
||||
impl<'a, T: PyValue> From<&'a PyRef<T>> for &'a PyObjectRef {
|
||||
fn from(obj: &'a PyRef<T>) -> Self {
|
||||
obj.as_object()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PyValue> From<PyRef<T>> for PyObjectRef {
|
||||
fn from(obj: PyRef<T>) -> Self {
|
||||
obj.into_object()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: fmt::Display> fmt::Display for PyRef<T>
|
||||
where
|
||||
T: PyObjectPayload + fmt::Display,
|
||||
@@ -507,7 +495,7 @@ impl<T: PyValue> Deref for PyRefExact<T> {
|
||||
impl<T: PyValue> IntoPyObject for PyRefExact<T> {
|
||||
#[inline]
|
||||
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.obj.into_object()
|
||||
self.obj.into()
|
||||
}
|
||||
}
|
||||
impl<T: PyValue> TryIntoRef<T> for PyRefExact<T> {
|
||||
@@ -816,7 +804,7 @@ where
|
||||
impl<T: PyObjectPayload> IntoPyObject for PyRef<T> {
|
||||
#[inline]
|
||||
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.into_object()
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -872,7 +860,7 @@ pub trait PyValue: fmt::Debug + PyThreadingConstraint + Sized + 'static {
|
||||
|
||||
#[inline]
|
||||
fn into_object(self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.into_ref(vm).into_object()
|
||||
self.into_ref(vm).into()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -1005,8 +993,7 @@ pub trait PyClassImpl: PyClassDef {
|
||||
class.set_str_attr("__module__", ctx.new_utf8_str(module_name));
|
||||
}
|
||||
if class.slots.new.load().is_some() {
|
||||
let bound =
|
||||
ctx.new_bound_method(ctx.slot_new_wrapper.clone(), class.clone().into_object());
|
||||
let bound = ctx.new_bound_method(ctx.slot_new_wrapper.clone(), class.clone().into());
|
||||
class.set_str_attr("__new__", bound);
|
||||
}
|
||||
}
|
||||
@@ -1080,7 +1067,7 @@ pub trait PyStructSequence: StaticType + PyClassImpl + Sized + 'static {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<PyTuple>, vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.ctx.new_tuple(vec![
|
||||
zelf.clone_class().into_object(),
|
||||
zelf.clone_class().into(),
|
||||
vm.ctx
|
||||
.new_tuple(vec![vm.ctx.new_tuple(zelf.as_slice().to_vec())]),
|
||||
])
|
||||
@@ -1187,7 +1174,7 @@ impl PyMethod {
|
||||
.is_some()
|
||||
{
|
||||
drop(descr_cls);
|
||||
let cls = PyLease::into_pyref(cls).into_object();
|
||||
let cls = PyLease::into_pyref(cls).into();
|
||||
return descr_get(descr, Some(obj), Some(cls), vm).map(Self::Attribute);
|
||||
}
|
||||
}
|
||||
@@ -1215,7 +1202,7 @@ impl PyMethod {
|
||||
})
|
||||
}
|
||||
Some(descr_get) => {
|
||||
let cls = PyLease::into_pyref(cls).into_object();
|
||||
let cls = PyLease::into_pyref(cls).into();
|
||||
descr_get(attr, Some(obj), Some(cls), vm).map(Self::Attribute)
|
||||
}
|
||||
None => Ok(Self::Attribute(attr)),
|
||||
@@ -1254,7 +1241,7 @@ impl PyMethod {
|
||||
drop(obj_cls);
|
||||
Self::Function { target: obj, func }
|
||||
} else {
|
||||
let obj_cls = PyLease::into_pyref(obj_cls).into_object();
|
||||
let obj_cls = PyLease::into_pyref(obj_cls).into();
|
||||
let attr = vm
|
||||
.call_get_descriptor_specific(func, Some(obj), Some(obj_cls))
|
||||
.unwrap_or_else(Ok)?;
|
||||
|
||||
+51
-5
@@ -139,6 +139,18 @@ pub struct PyObjectWeak {
|
||||
weak: PyWeak<PyObject<Erased>>,
|
||||
}
|
||||
|
||||
pub trait PyObjectWrap
|
||||
where
|
||||
Self: AsRef<PyObjectRef>,
|
||||
{
|
||||
#[inline(always)]
|
||||
fn as_object(&self) -> &PyObjectRef {
|
||||
self.as_ref()
|
||||
}
|
||||
|
||||
fn into_object(self) -> PyObjectRef;
|
||||
}
|
||||
|
||||
/// A marker type that just references a raw python object. Don't use directly, pass as a pointer
|
||||
/// back to [`PyObjectRef::from_raw`]
|
||||
pub enum RawPyObject {}
|
||||
@@ -283,12 +295,33 @@ impl PyObjectRef {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Self> for PyObjectRef {
|
||||
fn as_ref(&self) -> &Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl IdProtocol for PyObjectRef {
|
||||
fn get_id(&self) -> usize {
|
||||
self.rc.get_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: PyObjectPayload> From<&'a PyRef<T>> for &'a PyObjectRef {
|
||||
fn from(py_ref: &'a PyRef<T>) -> Self {
|
||||
&py_ref.obj
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<T> for PyObjectRef
|
||||
where
|
||||
T: PyObjectWrap,
|
||||
{
|
||||
fn from(py_ref: T) -> Self {
|
||||
py_ref.into_object()
|
||||
}
|
||||
}
|
||||
|
||||
impl PyObjectWeak {
|
||||
pub fn upgrade(&self) -> Option<PyObjectRef> {
|
||||
self.weak.upgrade().map(|rc| PyObjectRef { rc })
|
||||
@@ -394,11 +427,6 @@ impl<T: PyObjectPayload> PyRef<T> {
|
||||
&self.obj
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn into_object(self) -> PyObjectRef {
|
||||
self.obj
|
||||
}
|
||||
|
||||
pub fn downgrade(this: &Self) -> PyWeakRef<T> {
|
||||
PyWeakRef {
|
||||
weak: PyObjectRef::downgrade(&this.obj),
|
||||
@@ -418,6 +446,24 @@ impl<T: PyObjectPayload> PyRef<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PyObjectWrap for PyRef<T>
|
||||
where
|
||||
T: PyObjectPayload,
|
||||
{
|
||||
fn into_object(self) -> PyObjectRef {
|
||||
self.obj
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AsRef<PyObjectRef> for PyRef<T>
|
||||
where
|
||||
T: PyObjectPayload,
|
||||
{
|
||||
fn as_ref(&self) -> &PyObjectRef {
|
||||
&self.obj
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for PyRef<T>
|
||||
where
|
||||
T: PyObjectPayload,
|
||||
|
||||
@@ -46,7 +46,7 @@ pub(crate) struct AstNode;
|
||||
impl AstNode {
|
||||
#[pymethod(magic)]
|
||||
fn init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
|
||||
let fields = vm.get_attribute(zelf.clone_class().into_object(), "_fields")?;
|
||||
let fields = vm.get_attribute(zelf.clone_class().into(), "_fields")?;
|
||||
let fields = vm.extract_elements::<PyStrRef>(&fields)?;
|
||||
let numargs = args.args.len();
|
||||
if numargs > fields.len() {
|
||||
@@ -269,7 +269,7 @@ pub(crate) fn compile(
|
||||
let code = rustpython_compiler_core::compile::compile_top(&ast, filename.to_owned(), opts)
|
||||
// TODO: use vm.new_syntax_error()
|
||||
.map_err(|err| vm.new_value_error(err.to_string()))?;
|
||||
Ok(vm.new_code_object(code).into_object())
|
||||
Ok(vm.new_code_object(code).into())
|
||||
}
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
|
||||
+96
-96
@@ -975,26 +975,26 @@ impl Node for ast::Mod {
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("type_ignores", type_ignores.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Mod::Interactive { body } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeInteractive::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Mod::Expression { body } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeExpression::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Mod::FunctionType { argtypes,returns } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeFunctionType::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("argtypes", argtypes.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("returns", returns.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1043,7 +1043,7 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("decorator_list", decorator_list.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("returns", returns.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("type_comment", type_comment.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::AsyncFunctionDef { name,args,body,decorator_list,returns,type_comment } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeAsyncFunctionDef::static_type().clone()).unwrap();
|
||||
@@ -1054,7 +1054,7 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("decorator_list", decorator_list.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("returns", returns.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("type_comment", type_comment.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::ClassDef { name,bases,keywords,body,decorator_list } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeClassDef::static_type().clone()).unwrap();
|
||||
@@ -1064,19 +1064,19 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("keywords", keywords.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("decorator_list", decorator_list.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Return { value } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeReturn::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Delete { targets } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeDelete::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("targets", targets.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Assign { targets,value,type_comment } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeAssign::static_type().clone()).unwrap();
|
||||
@@ -1084,7 +1084,7 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("targets", targets.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("type_comment", type_comment.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::AugAssign { target,op,value } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeAugAssign::static_type().clone()).unwrap();
|
||||
@@ -1092,7 +1092,7 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("target", target.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("op", op.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::AnnAssign { target,annotation,value,simple } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeAnnAssign::static_type().clone()).unwrap();
|
||||
@@ -1101,7 +1101,7 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("annotation", annotation.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("simple", simple.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::For { target,iter,body,orelse,type_comment } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeFor::static_type().clone()).unwrap();
|
||||
@@ -1111,7 +1111,7 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("orelse", orelse.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("type_comment", type_comment.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::AsyncFor { target,iter,body,orelse,type_comment } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeAsyncFor::static_type().clone()).unwrap();
|
||||
@@ -1121,7 +1121,7 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("orelse", orelse.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("type_comment", type_comment.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::While { test,body,orelse } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeWhile::static_type().clone()).unwrap();
|
||||
@@ -1129,7 +1129,7 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("test", test.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("orelse", orelse.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::If { test,body,orelse } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeIf::static_type().clone()).unwrap();
|
||||
@@ -1137,7 +1137,7 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("test", test.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("orelse", orelse.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::With { items,body,type_comment } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeWith::static_type().clone()).unwrap();
|
||||
@@ -1145,7 +1145,7 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("items", items.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("type_comment", type_comment.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::AsyncWith { items,body,type_comment } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeAsyncWith::static_type().clone()).unwrap();
|
||||
@@ -1153,14 +1153,14 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("items", items.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("type_comment", type_comment.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Raise { exc,cause } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeRaise::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("exc", exc.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("cause", cause.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Try { body,handlers,orelse,finalbody } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeTry::static_type().clone()).unwrap();
|
||||
@@ -1169,20 +1169,20 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("handlers", handlers.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("orelse", orelse.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("finalbody", finalbody.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Assert { test,msg } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeAssert::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("test", test.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("msg", msg.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Import { names } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeImport::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("names", names.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::ImportFrom { module,names,level } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeImportFrom::static_type().clone()).unwrap();
|
||||
@@ -1190,37 +1190,37 @@ impl Node for ast::StmtKind {
|
||||
_dict.set_item("module", module.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("names", names.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("level", level.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Global { names } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeGlobal::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("names", names.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Nonlocal { names } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeNonlocal::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("names", names.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Expr { value } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeExpr::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Pass { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodePass::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Break { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeBreak::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::StmtKind::Continue { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeContinue::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1410,14 +1410,14 @@ impl Node for ast::ExprKind {
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("op", op.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("values", values.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::NamedExpr { target,value } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeNamedExpr::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("target", target.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::BinOp { left,op,right } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeBinOp::static_type().clone()).unwrap();
|
||||
@@ -1425,21 +1425,21 @@ impl Node for ast::ExprKind {
|
||||
_dict.set_item("left", left.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("op", op.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("right", right.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::UnaryOp { op,operand } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeUnaryOp::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("op", op.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("operand", operand.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Lambda { args,body } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeLambda::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("args", args.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::IfExp { test,body,orelse } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeIfExp::static_type().clone()).unwrap();
|
||||
@@ -1447,34 +1447,34 @@ impl Node for ast::ExprKind {
|
||||
_dict.set_item("test", test.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("orelse", orelse.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Dict { keys,values } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeDict::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("keys", keys.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("values", values.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Set { elts } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeSet::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("elts", elts.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::ListComp { elt,generators } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeListComp::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("elt", elt.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("generators", generators.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::SetComp { elt,generators } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeSetComp::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("elt", elt.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("generators", generators.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::DictComp { key,value,generators } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeDictComp::static_type().clone()).unwrap();
|
||||
@@ -1482,32 +1482,32 @@ impl Node for ast::ExprKind {
|
||||
_dict.set_item("key", key.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("generators", generators.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::GeneratorExp { elt,generators } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeGeneratorExp::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("elt", elt.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("generators", generators.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Await { value } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeAwait::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Yield { value } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeYield::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::YieldFrom { value } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeYieldFrom::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Compare { left,ops,comparators } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeCompare::static_type().clone()).unwrap();
|
||||
@@ -1515,7 +1515,7 @@ impl Node for ast::ExprKind {
|
||||
_dict.set_item("left", left.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("ops", ops.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("comparators", comparators.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Call { func,args,keywords } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeCall::static_type().clone()).unwrap();
|
||||
@@ -1523,7 +1523,7 @@ impl Node for ast::ExprKind {
|
||||
_dict.set_item("func", func.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("args", args.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("keywords", keywords.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::FormattedValue { value,conversion,format_spec } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeFormattedValue::static_type().clone()).unwrap();
|
||||
@@ -1531,20 +1531,20 @@ impl Node for ast::ExprKind {
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("conversion", conversion.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("format_spec", format_spec.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::JoinedStr { values } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeJoinedStr::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("values", values.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Constant { value,kind } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeConstant::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("kind", kind.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Attribute { value,attr,ctx } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeAttribute::static_type().clone()).unwrap();
|
||||
@@ -1552,7 +1552,7 @@ impl Node for ast::ExprKind {
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("attr", attr.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Subscript { value,slice,ctx } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeSubscript::static_type().clone()).unwrap();
|
||||
@@ -1560,35 +1560,35 @@ impl Node for ast::ExprKind {
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("slice", slice.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Starred { value,ctx } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeStarred::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Name { id,ctx } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeName::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("id", id.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::List { elts,ctx } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeList::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("elts", elts.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Tuple { elts,ctx } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeTuple::static_type().clone()).unwrap();
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("elts", elts.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprKind::Slice { lower,upper,step } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeSlice::static_type().clone()).unwrap();
|
||||
@@ -1596,7 +1596,7 @@ impl Node for ast::ExprKind {
|
||||
_dict.set_item("lower", lower.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("upper", upper.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("step", step.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1783,15 +1783,15 @@ impl Node for ast::ExprContext {
|
||||
match self {
|
||||
ast::ExprContext::Load { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeLoad::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprContext::Store { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeStore::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::ExprContext::Del { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeDel::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1823,11 +1823,11 @@ impl Node for ast::Boolop {
|
||||
match self {
|
||||
ast::Boolop::And { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeAnd::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Boolop::Or { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeOr::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1855,55 +1855,55 @@ impl Node for ast::Operator {
|
||||
match self {
|
||||
ast::Operator::Add { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeAdd::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::Sub { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeSub::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::Mult { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeMult::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::MatMult { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeMatMult::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::Div { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeDiv::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::Mod { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeMod::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::Pow { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodePow::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::LShift { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeLShift::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::RShift { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeRShift::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::BitOr { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeBitOr::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::BitXor { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeBitXor::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::BitAnd { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeBitAnd::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Operator::FloorDiv { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeFloorDiv::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1975,19 +1975,19 @@ impl Node for ast::Unaryop {
|
||||
match self {
|
||||
ast::Unaryop::Invert { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeInvert::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Unaryop::Not { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeNot::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Unaryop::UAdd { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeUAdd::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Unaryop::USub { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeUSub::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2023,43 +2023,43 @@ impl Node for ast::Cmpop {
|
||||
match self {
|
||||
ast::Cmpop::Eq { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeEq::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Cmpop::NotEq { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeNotEq::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Cmpop::Lt { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeLt::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Cmpop::LtE { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeLtE::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Cmpop::Gt { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeGt::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Cmpop::GtE { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeGtE::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Cmpop::Is { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeIs::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Cmpop::IsNot { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeIsNot::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Cmpop::In { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeIn::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
ast::Cmpop::NotIn { } => {
|
||||
let _node = AstNode.into_ref_with_type(_vm, NodeNotIn::static_type().clone()).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2123,7 +2123,7 @@ impl Node for ast::Comprehension {
|
||||
_dict.set_item("iter", iter.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("ifs", ifs.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("is_async", is_async.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult<Self> {
|
||||
Ok(
|
||||
@@ -2148,7 +2148,7 @@ impl Node for ast::ExcepthandlerKind {
|
||||
_dict.set_item("type", type_.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("name", name.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("body", body.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2183,7 +2183,7 @@ impl Node for ast::Arguments {
|
||||
_dict.set_item("kw_defaults", kw_defaults.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("kwarg", kwarg.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("defaults", defaults.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult<Self> {
|
||||
Ok(
|
||||
@@ -2210,7 +2210,7 @@ impl Node for ast::ArgData {
|
||||
_dict.set_item("arg", arg.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("annotation", annotation.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("type_comment", type_comment.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult<Self> {
|
||||
let _location = ast::Location::new(Node::ast_from_object(_vm, get_node_field(_vm, &_object, "lineno", "arg")?)?, Node::ast_from_object(_vm, get_node_field(_vm, &_object, "col_offset", "arg")?)?);
|
||||
@@ -2233,7 +2233,7 @@ impl Node for ast::KeywordData {
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("arg", arg.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("value", value.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult<Self> {
|
||||
let _location = ast::Location::new(Node::ast_from_object(_vm, get_node_field(_vm, &_object, "lineno", "keyword")?)?, Node::ast_from_object(_vm, get_node_field(_vm, &_object, "col_offset", "keyword")?)?);
|
||||
@@ -2255,7 +2255,7 @@ impl Node for ast::Alias {
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("name", name.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("asname", asname.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult<Self> {
|
||||
Ok(
|
||||
@@ -2276,7 +2276,7 @@ impl Node for ast::Withitem {
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("context_expr", context_expr.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("optional_vars", optional_vars.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult<Self> {
|
||||
Ok(
|
||||
@@ -2298,7 +2298,7 @@ impl Node for ast::TypeIgnore {
|
||||
let _dict = _node.as_object().dict().unwrap();
|
||||
_dict.set_item("lineno", lineno.ast_to_object(_vm), _vm).unwrap();
|
||||
_dict.set_item("tag", tag.ast_to_object(_vm), _vm).unwrap();
|
||||
_node.into_object()
|
||||
_node.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-13
@@ -169,10 +169,10 @@ mod builtins {
|
||||
let mode = mode_str
|
||||
.parse::<compile::Mode>()
|
||||
.map_err(|err| vm.new_value_error(err.to_string()))?;
|
||||
|
||||
vm.compile(source, mode, args.filename.as_str().to_owned())
|
||||
.map(|o| o.into_object())
|
||||
.map_err(|err| vm.new_syntax_error(&err))
|
||||
let code = vm
|
||||
.compile(source, mode, args.filename.as_str().to_owned())
|
||||
.map_err(|err| vm.new_syntax_error(&err))?;
|
||||
Ok(code.into())
|
||||
}
|
||||
} else {
|
||||
let mode = mode_str
|
||||
@@ -186,7 +186,7 @@ mod builtins {
|
||||
|
||||
#[pyfunction]
|
||||
fn delattr(obj: PyObjectRef, attr: PyStrRef, vm: &VirtualMachine) -> PyResult<()> {
|
||||
vm.del_attr(&obj, attr.into_object())
|
||||
vm.del_attr(&obj, attr)
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
@@ -223,7 +223,7 @@ mod builtins {
|
||||
let (globals, locals) = match self.globals {
|
||||
Some(globals) => {
|
||||
if !globals.contains_key("__builtins__", vm) {
|
||||
let builtins_dict = vm.builtins.dict().unwrap().into_object();
|
||||
let builtins_dict = vm.builtins.dict().unwrap().into();
|
||||
globals.set_item("__builtins__", builtins_dict, vm)?;
|
||||
}
|
||||
let locals = self.locals.unwrap_or_else(|| globals.clone());
|
||||
@@ -421,7 +421,7 @@ mod builtins {
|
||||
let callable = ArgCallable::try_from_object(vm, iter_target)?;
|
||||
let iterator = PyCallableIterator::new(callable, sentinel)
|
||||
.into_ref(vm)
|
||||
.into_object();
|
||||
.into();
|
||||
Ok(PyIter::new(iterator))
|
||||
} else {
|
||||
iter_target.get_iter(vm)
|
||||
@@ -738,7 +738,7 @@ mod builtins {
|
||||
value: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
vm.set_attr(&obj, attr.into_object(), value)?;
|
||||
vm.set_attr(&obj, attr, value)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -799,7 +799,7 @@ mod builtins {
|
||||
vm.new_type_error("vars() argument must have __dict__ attribute".to_owned())
|
||||
})
|
||||
} else {
|
||||
Ok(vm.current_locals()?.into_object())
|
||||
Ok(vm.current_locals()?.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -867,10 +867,10 @@ mod builtins {
|
||||
}
|
||||
}
|
||||
|
||||
let bases = bases.into_object();
|
||||
let bases: PyObjectRef = bases.into();
|
||||
|
||||
// Prepare uses full __getattribute__ resolution chain.
|
||||
let prepare = vm.get_attribute(metaclass.clone().into_object(), "__prepare__")?;
|
||||
let prepare = vm.get_attribute(metaclass.clone().into(), "__prepare__")?;
|
||||
let namespace = vm.invoke(
|
||||
&prepare,
|
||||
FuncArgs::new(vec![name_obj.clone(), bases.clone()], kwargs.clone()),
|
||||
@@ -882,12 +882,12 @@ mod builtins {
|
||||
let classcell = <Option<PyCellRef>>::try_from_object(vm, classcell)?;
|
||||
|
||||
if let Some(orig_bases) = orig_bases {
|
||||
namespace.set_item("__orig_bases__", orig_bases.into_object(), vm)?;
|
||||
namespace.set_item("__orig_bases__", orig_bases.into(), vm)?;
|
||||
}
|
||||
|
||||
let class = vm.invoke(
|
||||
metaclass.as_object(),
|
||||
FuncArgs::new(vec![name_obj, bases, namespace.into_object()], kwargs),
|
||||
FuncArgs::new(vec![name_obj, bases, namespace.into()], kwargs),
|
||||
)?;
|
||||
|
||||
if let Some(ref classcell) = classcell {
|
||||
|
||||
@@ -21,7 +21,7 @@ mod _codecs {
|
||||
vm.state
|
||||
.codec_registry
|
||||
.lookup(encoding.as_str(), vm)
|
||||
.map(|codec| codec.into_tuple().into_object())
|
||||
.map(|codec| codec.into_tuple().into())
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
|
||||
@@ -521,24 +521,12 @@ mod _collections {
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult {
|
||||
let cls = zelf.clone_class().into_object();
|
||||
Ok(match zelf.maxlen {
|
||||
Some(v) => vm.ctx.new_tuple(vec![
|
||||
cls,
|
||||
vm.ctx.new_tuple(vec![
|
||||
vm.ctx.empty_tuple.clone().into_object(),
|
||||
vm.ctx.new_int(v),
|
||||
]),
|
||||
vm.ctx.none(),
|
||||
PyDequeIterator::new(zelf).into_object(vm),
|
||||
]),
|
||||
None => vm.ctx.new_tuple(vec![
|
||||
cls,
|
||||
vm.ctx.empty_tuple.clone().into_object(),
|
||||
vm.ctx.none(),
|
||||
PyDequeIterator::new(zelf).into_object(vm),
|
||||
]),
|
||||
})
|
||||
let cls = zelf.clone_class();
|
||||
let value = match zelf.maxlen {
|
||||
Some(v) => vm.new_pyobj((vm.ctx.empty_tuple.clone(), v)),
|
||||
None => vm.ctx.empty_tuple.clone().into(),
|
||||
};
|
||||
Ok(vm.new_pyobj((cls, value, vm.ctx.none(), PyDequeIterator::new(zelf))))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ fn _imp_create_builtin(spec: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
|
||||
if let Ok(module) = sys_modules.get_item(name.clone(), vm) {
|
||||
Ok(module)
|
||||
} else if let Some(make_module_func) = vm.state.module_inits.get(name.as_ref()) {
|
||||
} else if let Some(make_module_func) = vm.state.module_inits.get(name.as_str()) {
|
||||
Ok(make_module_func(vm))
|
||||
} else {
|
||||
Ok(vm.ctx.none())
|
||||
|
||||
+1
-1
@@ -2418,7 +2418,7 @@ mod _io {
|
||||
let start_of_stream = cookie.start_pos == 0 && cookie.dec_flags == 0;
|
||||
reset_encoder(encoder, start_of_stream)?;
|
||||
}
|
||||
Ok(cookie_obj.into_object())
|
||||
Ok(cookie_obj.into())
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
|
||||
@@ -492,7 +492,7 @@ mod decl {
|
||||
}
|
||||
};
|
||||
let pred = predicate.clone();
|
||||
let pred_value = vm.invoke(&pred.into_object(), (obj.clone(),))?;
|
||||
let pred_value = vm.invoke(&pred, (obj.clone(),))?;
|
||||
if !pred_value.try_to_bool(vm)? {
|
||||
zelf.start_flag.store(true);
|
||||
return Ok(PyIterReturn::Return(obj));
|
||||
@@ -1017,7 +1017,7 @@ mod decl {
|
||||
tee_vec.push(vm.call_method(©able, "__copy__", ())?);
|
||||
}
|
||||
|
||||
Ok(PyTupleRef::with_elements(tee_vec, &vm.ctx).into_object())
|
||||
Ok(PyTupleRef::with_elements(tee_vec, &vm.ctx).into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1033,17 +1033,15 @@ mod decl {
|
||||
index: AtomicCell::new(0),
|
||||
}
|
||||
.into_ref_with_type(vm, class.clone())?
|
||||
.into_object())
|
||||
.into())
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn copy(&self, vm: &VirtualMachine) -> PyResult {
|
||||
Ok(PyItertoolsTee {
|
||||
fn copy(&self) -> Self {
|
||||
Self {
|
||||
tee_data: PyRc::clone(&self.tee_data),
|
||||
index: AtomicCell::new(self.index.load()),
|
||||
}
|
||||
.into_ref_with_type(vm, Self::class(vm).clone())?
|
||||
.into_object())
|
||||
}
|
||||
}
|
||||
impl IteratorIterable for PyItertoolsTee {}
|
||||
|
||||
+1
-1
@@ -239,7 +239,7 @@ pub(crate) mod module {
|
||||
|
||||
let path = make_widestring(path.as_str())?;
|
||||
|
||||
let argv = vm.extract_elements_func(argv.as_object(), |obj| {
|
||||
let argv = vm.extract_elements_func(argv.as_ref(), |obj| {
|
||||
let arg = PyStrRef::try_from_object(vm, obj)?;
|
||||
make_widestring(arg.as_str())
|
||||
})?;
|
||||
|
||||
@@ -473,9 +473,7 @@ mod _operator {
|
||||
let attrs = vm
|
||||
.ctx
|
||||
.new_tuple(zelf.attrs.iter().map(|v| v.as_object()).cloned().collect());
|
||||
Ok(vm
|
||||
.ctx
|
||||
.new_tuple(vec![zelf.clone_class().into_object(), attrs]))
|
||||
Ok(vm.new_pyobj((zelf.clone_class(), attrs)))
|
||||
}
|
||||
|
||||
// Go through dotted parts of string and call getattr on whatever is returned.
|
||||
@@ -559,8 +557,7 @@ mod _operator {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyObjectRef {
|
||||
let items = vm.ctx.new_tuple(zelf.items.to_vec());
|
||||
vm.ctx
|
||||
.new_tuple(vec![zelf.clone_class().into_object(), items])
|
||||
vm.new_pyobj((zelf.clone_class(), items))
|
||||
}
|
||||
|
||||
fn call(zelf: &PyRef<Self>, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
@@ -647,10 +644,9 @@ mod _operator {
|
||||
if zelf.args.kwargs.is_empty() {
|
||||
let mut pargs = vec![zelf.name.as_object().to_owned()];
|
||||
pargs.append(&mut zelf.args.args.clone());
|
||||
Ok(vm.ctx.new_tuple(vec![
|
||||
zelf.clone_class().into_object(),
|
||||
vm.ctx.new_tuple(pargs),
|
||||
]))
|
||||
Ok(vm
|
||||
.ctx
|
||||
.new_tuple(vec![zelf.clone_class().into(), vm.ctx.new_tuple(pargs)]))
|
||||
} else {
|
||||
// If we have kwargs, create a partial function that contains them and pass back that
|
||||
// along with the args.
|
||||
@@ -658,10 +654,7 @@ mod _operator {
|
||||
let callable = vm.invoke(
|
||||
&partial,
|
||||
FuncArgs::new(
|
||||
vec![
|
||||
zelf.clone_class().into_object(),
|
||||
zelf.name.as_object().to_owned(),
|
||||
],
|
||||
vec![zelf.clone_class().into(), zelf.name.as_object().to_owned()],
|
||||
KwArgs::new(zelf.args.kwargs.clone()),
|
||||
),
|
||||
)?;
|
||||
|
||||
+7
-7
@@ -182,8 +182,8 @@ impl FsPath {
|
||||
impl IntoPyObject for FsPath {
|
||||
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
|
||||
match self {
|
||||
Self::Str(s) => s.into_object(),
|
||||
Self::Bytes(b) => b.into_object(),
|
||||
Self::Str(s) => s.into(),
|
||||
Self::Bytes(b) => b.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -914,7 +914,7 @@ pub(super) mod _os {
|
||||
ino: AtomicCell::new(None),
|
||||
}
|
||||
.into_ref(vm)
|
||||
.into_object(),
|
||||
.into(),
|
||||
)),
|
||||
Err(err) => Err(err.into_pyexception(vm)),
|
||||
},
|
||||
@@ -940,7 +940,7 @@ pub(super) mod _os {
|
||||
mode: path.mode,
|
||||
}
|
||||
.into_ref(vm)
|
||||
.into_object())
|
||||
.into())
|
||||
}
|
||||
|
||||
#[pyattr]
|
||||
@@ -1744,9 +1744,9 @@ pub fn extend_module(vm: &VirtualMachine, module: &PyObjectRef) {
|
||||
}
|
||||
|
||||
extend_module!(vm, module, {
|
||||
"supports_fd" => supports_fd.into_object(),
|
||||
"supports_dir_fd" => supports_dir_fd.into_object(),
|
||||
"supports_follow_symlinks" => supports_follow_symlinks.into_object(),
|
||||
"supports_fd" => supports_fd,
|
||||
"supports_dir_fd" => supports_dir_fd,
|
||||
"supports_follow_symlinks" => supports_follow_symlinks,
|
||||
"error" => vm.ctx.exceptions.os_error.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -774,7 +774,7 @@ pub mod module {
|
||||
) -> PyResult<()> {
|
||||
let path = path.into_cstring(vm)?;
|
||||
|
||||
let argv = vm.extract_elements_func(argv.as_object(), |obj| {
|
||||
let argv = vm.extract_elements_func(argv.as_ref(), |obj| {
|
||||
PyStrRef::try_from_object(vm, obj)?.to_cstring(vm)
|
||||
})?;
|
||||
let argv: Vec<&CStr> = argv.iter().map(|entry| entry.as_c_str()).collect();
|
||||
@@ -802,7 +802,7 @@ pub mod module {
|
||||
) -> PyResult<()> {
|
||||
let path = path.into_cstring(vm)?;
|
||||
|
||||
let argv = vm.extract_elements_func(argv.as_object(), |obj| {
|
||||
let argv = vm.extract_elements_func(argv.as_ref(), |obj| {
|
||||
PyStrRef::try_from_object(vm, obj)?.to_cstring(vm)
|
||||
})?;
|
||||
let argv: Vec<&CStr> = argv.iter().map(|entry| entry.as_c_str()).collect();
|
||||
|
||||
@@ -839,7 +839,7 @@ pub(crate) mod _struct {
|
||||
if let Some(buf) = buf.get(offset..offset + size) {
|
||||
zelf.format_spec
|
||||
.unpack(buf, vm)
|
||||
.map(|x| PyIterReturn::Return(x.into_object()))
|
||||
.map(|x| PyIterReturn::Return(x.into()))
|
||||
} else {
|
||||
Ok(PyIterReturn::StopIteration(None))
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ mod _sre {
|
||||
OptionalArg::Present(vm.ctx.new_ascii_literal(ascii!(""))),
|
||||
vm,
|
||||
)?
|
||||
.into_object()
|
||||
.into()
|
||||
};
|
||||
|
||||
matchlist.push(item);
|
||||
@@ -296,7 +296,7 @@ mod _sre {
|
||||
must_advance: AtomicCell::new(false),
|
||||
}
|
||||
.into_ref(vm);
|
||||
let search = vm.get_method(scanner.into_object(), "search").unwrap()?;
|
||||
let search = vm.get_method(scanner.into(), "search").unwrap()?;
|
||||
let search = ArgCallable::try_from_object(vm, search)?;
|
||||
let iterator = PyCallableIterator::new(search, vm.ctx.none());
|
||||
Ok(iterator)
|
||||
@@ -613,8 +613,8 @@ mod _sre {
|
||||
.and_then(|i| self.pattern.indexgroup.get(i).cloned().flatten())
|
||||
}
|
||||
#[pyproperty]
|
||||
fn re(&self) -> PyObjectRef {
|
||||
self.pattern.clone().into_object()
|
||||
fn re(&self) -> PyRef<Pattern> {
|
||||
self.pattern.clone()
|
||||
}
|
||||
#[pyproperty]
|
||||
fn string(&self) -> PyObjectRef {
|
||||
|
||||
@@ -126,7 +126,7 @@ mod symtable {
|
||||
.collect(),
|
||||
})
|
||||
.into_ref(vm)
|
||||
.into_object()
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
Ok(vm.ctx.new_list(symbols))
|
||||
@@ -243,7 +243,7 @@ mod symtable {
|
||||
} else {
|
||||
Ok(to_py_symbol_table(self.namespaces.first().unwrap().clone())
|
||||
.into_ref(vm)
|
||||
.into_object())
|
||||
.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ fn sys_displayhook(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
|
||||
// set to none to avoid recursion while printing
|
||||
vm.set_attr(&vm.builtins, "_", vm.ctx.none())?;
|
||||
// TODO: catch encoding errors
|
||||
let repr = vm.to_repr(&obj)?.into_object();
|
||||
let repr = vm.to_repr(&obj)?.into();
|
||||
builtins::print(PosArgs::new(vec![repr]), Default::default(), vm)?;
|
||||
vm.set_attr(&vm.builtins, "_", obj)?;
|
||||
Ok(())
|
||||
|
||||
@@ -253,7 +253,7 @@ fn run_thread(func: ArgCallable, args: FuncArgs, vm: &VirtualMachine) {
|
||||
// TODO: sys.unraisablehook
|
||||
let stderr = std::io::stderr();
|
||||
let mut stderr = py_io::IoWriter(stderr.lock());
|
||||
let repr = vm.to_repr(&func.into_object()).ok();
|
||||
let repr = vm.to_repr(func.as_ref()).ok();
|
||||
let repr = repr
|
||||
.as_ref()
|
||||
.map_or("<object repr() failed>", |s| s.as_str());
|
||||
@@ -319,12 +319,15 @@ impl SlotGetattro for PyLocal {
|
||||
fn getattro(zelf: PyRef<Self>, attr: PyStrRef, vm: &VirtualMachine) -> PyResult {
|
||||
let ldict = zelf.ldict(vm);
|
||||
if attr.as_str() == "__dict__" {
|
||||
Ok(ldict.into_object())
|
||||
Ok(ldict.into())
|
||||
} else {
|
||||
let zelf = zelf.into_object();
|
||||
vm.generic_getattribute_opt(zelf.clone(), attr.clone(), Some(ldict))?
|
||||
vm.generic_getattribute_opt(zelf.clone().into(), attr.clone(), Some(ldict))?
|
||||
.ok_or_else(|| {
|
||||
vm.new_attribute_error(format!("{} has no attribute '{}'", zelf, attr))
|
||||
vm.new_attribute_error(format!(
|
||||
"{} has no attribute '{}'",
|
||||
zelf.as_object(),
|
||||
attr
|
||||
))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ fn getattributelist(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<At
|
||||
<Option<PyMapping>>::try_from_object(vm, obj)?
|
||||
.map(|mapping| {
|
||||
let handlelist = mapping
|
||||
.into_object()
|
||||
.as_ref()
|
||||
.get_item("handle_list", vm)
|
||||
.ok()
|
||||
.and_then(|obj| {
|
||||
|
||||
+8
-6
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
builtins::{PyFloat, PyStr},
|
||||
function::{IntoPyException, IntoPyObject},
|
||||
PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
PyObjectRef, PyObjectWrap, PyResult, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
};
|
||||
use num_traits::ToPrimitive;
|
||||
|
||||
@@ -10,15 +10,17 @@ pub enum Either<A, B> {
|
||||
B(B),
|
||||
}
|
||||
|
||||
impl<A: PyValue, B: PyValue> Either<PyRef<A>, PyRef<B>> {
|
||||
pub fn as_object(&self) -> &PyObjectRef {
|
||||
impl<A: AsRef<PyObjectRef>, B: AsRef<PyObjectRef>> AsRef<PyObjectRef> for Either<A, B> {
|
||||
fn as_ref(&self) -> &PyObjectRef {
|
||||
match self {
|
||||
Either::A(a) => a.as_object(),
|
||||
Either::B(b) => b.as_object(),
|
||||
Either::A(a) => a.as_ref(),
|
||||
Either::B(b) => b.as_ref(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_object(self) -> PyObjectRef {
|
||||
impl<A: PyObjectWrap, B: PyObjectWrap> PyObjectWrap for Either<A, B> {
|
||||
fn into_object(self) -> PyObjectRef {
|
||||
match self {
|
||||
Either::A(a) => a.into_object(),
|
||||
Either::B(b) => b.into_object(),
|
||||
|
||||
+8
-7
@@ -1151,7 +1151,7 @@ impl VirtualMachine {
|
||||
descr: PyObjectRef,
|
||||
obj: PyObjectRef,
|
||||
) -> Result<PyResult, PyObjectRef> {
|
||||
let cls = obj.clone_class().into_object();
|
||||
let cls = obj.clone_class().into();
|
||||
self.call_get_descriptor_specific(descr, Some(obj), Some(cls))
|
||||
}
|
||||
|
||||
@@ -1210,11 +1210,12 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn invoke<T>(&self, func_ref: &PyObjectRef, args: T) -> PyResult
|
||||
pub fn invoke<O, A>(&self, func: &O, args: A) -> PyResult
|
||||
where
|
||||
T: IntoFuncArgs,
|
||||
O: AsRef<PyObjectRef>,
|
||||
A: IntoFuncArgs,
|
||||
{
|
||||
self._invoke(func_ref, args.into_args(self))
|
||||
self._invoke(func.as_ref(), args.into_args(self))
|
||||
}
|
||||
|
||||
/// Call registered trace function.
|
||||
@@ -1348,7 +1349,7 @@ impl VirtualMachine {
|
||||
}
|
||||
}
|
||||
|
||||
let mut results = PyIterIter::new(self, iter.as_object(), cap)
|
||||
let mut results = PyIterIter::new(self, iter.as_ref(), cap)
|
||||
.map(|element| f(element?))
|
||||
.collect::<PyResult<Vec<_>>>()?;
|
||||
results.shrink_to_fit();
|
||||
@@ -1528,7 +1529,7 @@ impl VirtualMachine {
|
||||
.is_some()
|
||||
{
|
||||
drop(descr_cls);
|
||||
let cls = PyLease::into_pyref(obj_cls).into_object();
|
||||
let cls = PyLease::into_pyref(obj_cls).into();
|
||||
return descr_get(descr, Some(obj), Some(cls), self).map(Some);
|
||||
}
|
||||
}
|
||||
@@ -1551,7 +1552,7 @@ impl VirtualMachine {
|
||||
} else if let Some((attr, descr_get)) = cls_attr {
|
||||
match descr_get {
|
||||
Some(descr_get) => {
|
||||
let cls = PyLease::into_pyref(obj_cls).into_object();
|
||||
let cls = PyLease::into_pyref(obj_cls).into();
|
||||
descr_get(attr, Some(obj), Some(cls), self).map(Some)
|
||||
}
|
||||
None => Ok(Some(attr)),
|
||||
|
||||
@@ -124,7 +124,7 @@ fn browser_request_animation_frame(func: ArgCallable, vm: &VirtualMachine) -> Py
|
||||
stored_vm.interp.enter(|vm| {
|
||||
let func = func.clone();
|
||||
let args = vec![vm.ctx.new_float(time)];
|
||||
let _ = vm.invoke(&func.into_object(), args);
|
||||
let _ = vm.invoke(&func, args);
|
||||
|
||||
let closure = f.borrow_mut().take();
|
||||
drop(closure);
|
||||
|
||||
@@ -176,7 +176,7 @@ pub fn js_to_py(vm: &VirtualMachine, js_val: JsValue) -> PyObjectRef {
|
||||
if vm.try_class("browser", "Promise").is_ok() {
|
||||
return js_module::PyPromise::new(promise.clone())
|
||||
.into_ref(vm)
|
||||
.into_object();
|
||||
.into();
|
||||
}
|
||||
}
|
||||
if Array::is_array(&js_val) {
|
||||
@@ -211,7 +211,7 @@ pub fn js_to_py(vm: &VirtualMachine, js_val: JsValue) -> PyObjectRef {
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
dict.into_object()
|
||||
dict.into()
|
||||
}
|
||||
} else if js_val.is_function() {
|
||||
let func = js_sys::Function::from(js_val);
|
||||
@@ -234,7 +234,7 @@ pub fn js_to_py(vm: &VirtualMachine, js_val: JsValue) -> PyObjectRef {
|
||||
},
|
||||
)
|
||||
} else if let Some(err) = js_val.dyn_ref::<js_sys::Error>() {
|
||||
js_err_to_py_err(vm, err).into_object()
|
||||
js_err_to_py_err(vm, err).into()
|
||||
} else if js_val.is_undefined() {
|
||||
// Because `JSON.stringify(undefined)` returns undefined
|
||||
vm.ctx.none()
|
||||
|
||||
+15
-12
@@ -1,19 +1,22 @@
|
||||
use crate::convert;
|
||||
use crate::vm_class::{stored_vm_from_wasm, WASMVirtualMachine};
|
||||
use crate::weak_vm;
|
||||
use crate::{
|
||||
convert,
|
||||
vm_class::{stored_vm_from_wasm, WASMVirtualMachine},
|
||||
weak_vm,
|
||||
};
|
||||
use js_sys::{Array, Object, Promise, Reflect};
|
||||
use std::{cell, fmt, future};
|
||||
use wasm_bindgen::{closure::Closure, prelude::*, JsCast};
|
||||
use wasm_bindgen_futures::{future_to_promise, JsFuture};
|
||||
|
||||
use rustpython_vm::{
|
||||
builtins::{PyBaseExceptionRef, PyFloatRef, PyStrRef, PyTypeRef},
|
||||
function::{ArgCallable, IntoPyObject, OptionalArg, OptionalOption, PosArgs},
|
||||
protocol::PyIterReturn,
|
||||
slots::{IteratorIterable, SlotIterator},
|
||||
types::create_simple_type,
|
||||
PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
|
||||
PyClassImpl, PyObjectRef, PyObjectWrap, PyRef, PyResult, PyValue, TryFromObject,
|
||||
VirtualMachine,
|
||||
};
|
||||
use std::ops::Deref;
|
||||
use std::{cell, fmt, future};
|
||||
use wasm_bindgen::{closure::Closure, prelude::*, JsCast};
|
||||
use wasm_bindgen_futures::{future_to_promise, JsFuture};
|
||||
|
||||
#[wasm_bindgen(inline_js = "
|
||||
export function has_prop(target, prop) { return prop in Object(target); }
|
||||
@@ -172,7 +175,7 @@ impl PyJsValue {
|
||||
.value
|
||||
.dyn_ref::<js_sys::Function>()
|
||||
.ok_or_else(|| vm.new_type_error("JS value is not callable".to_owned()))?;
|
||||
let js_args = args.iter().map(|x| x.as_ref()).collect::<Array>();
|
||||
let js_args = args.iter().map(|x| x.deref()).collect::<Array>();
|
||||
let res = match opts.this {
|
||||
Some(this) => Reflect::apply(func, &this.value, &js_args),
|
||||
None => call_func(func, &js_args),
|
||||
@@ -187,7 +190,7 @@ impl PyJsValue {
|
||||
args: PosArgs<PyJsValueRef>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyJsValue> {
|
||||
let js_args = args.iter().map(|x| x.as_ref()).collect::<Array>();
|
||||
let js_args = args.iter().map(|x| x.deref()).collect::<Array>();
|
||||
call_method(&self.value, &name.into_jsvalue(), &js_args)
|
||||
.map(PyJsValue::new)
|
||||
.map_err(|err| new_js_error(vm, err))
|
||||
@@ -208,7 +211,7 @@ impl PyJsValue {
|
||||
.prototype
|
||||
.as_ref()
|
||||
.and_then(|proto| proto.value.dyn_ref::<js_sys::Function>());
|
||||
let js_args = args.iter().map(|x| x.as_ref()).collect::<Array>();
|
||||
let js_args = args.iter().map(|x| x.deref()).collect::<Array>();
|
||||
let constructed_result = if let Some(proto) = proto {
|
||||
Reflect::construct_with_new_target(ctor, &js_args, proto)
|
||||
} else {
|
||||
@@ -530,7 +533,7 @@ impl PyPromise {
|
||||
#[pymethod(name = "__await__")]
|
||||
fn r#await(zelf: PyRef<Self>) -> AwaitPromise {
|
||||
AwaitPromise {
|
||||
obj: Some(zelf.into_object()).into(),
|
||||
obj: Some(zelf.into()).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user