Introduce AsPyObject to replace IdProtocol

This commit is contained in:
Jeong Yunwon
2022-04-17 08:20:28 +09:00
parent 9be1dc1f8b
commit 625f8675ae
68 changed files with 141 additions and 161 deletions

View File

@@ -51,8 +51,8 @@ use rustpython_vm::{
compile, match_class,
scope::Scope,
stdlib::{atexit, sys},
InitParameter, Interpreter, PyObjectRef, PyResult, PySettings, TryFromObject, TypeProtocol,
VirtualMachine,
AsPyObject, InitParameter, Interpreter, PyObjectRef, PyResult, PySettings, TryFromObject,
TypeProtocol, VirtualMachine,
};
use std::{env, path::Path, process, str::FromStr};
@@ -536,12 +536,8 @@ fn setup_main_module(vm: &VirtualMachine) -> PyResult<Scope> {
main_module
.dict()
.and_then(|d| {
d.set_item(
"__annotations__",
vm.ctx.new_dict().as_object().to_owned(),
vm,
)
.ok()
d.set_item("__annotations__", vm.ctx.new_dict().into(), vm)
.ok()
})
.expect("Failed to initialize __main__.__annotations__");

View File

@@ -85,9 +85,8 @@ impl<'vm> ShellHelper<'vm> {
} else {
// we need to get a variable based off of globals/builtins
let globals = str_iter_method(self.globals.as_object().to_owned(), "keys").ok()?;
let builtins =
str_iter_method(self.vm.builtins.as_object().to_owned(), "__dir__").ok()?;
let globals = str_iter_method(self.globals.clone().into(), "keys").ok()?;
let builtins = str_iter_method(self.vm.builtins.clone().into(), "__dir__").ok()?;
(first, globals, Some(builtins))
};
Some((word_start, iter1.chain(iter2.into_iter().flatten())))