Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 625f867

Browse files
committed
Introduce AsPyObject to replace IdProtocol
1 parent 9be1dc1 commit 625f867

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+139
-159
lines changed

src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ use rustpython_vm::{
5151
compile, match_class,
5252
scope::Scope,
5353
stdlib::{atexit, sys},
54-
InitParameter, Interpreter, PyObjectRef, PyResult, PySettings, TryFromObject, TypeProtocol,
55-
VirtualMachine,
54+
AsPyObject, InitParameter, Interpreter, PyObjectRef, PyResult, PySettings, TryFromObject,
55+
TypeProtocol, VirtualMachine,
5656
};
5757
use std::{env, path::Path, process, str::FromStr};
5858

@@ -536,12 +536,8 @@ fn setup_main_module(vm: &VirtualMachine) -> PyResult<Scope> {
536536
main_module
537537
.dict()
538538
.and_then(|d| {
539-
d.set_item(
540-
"__annotations__",
541-
vm.ctx.new_dict().as_object().to_owned(),
542-
vm,
543-
)
544-
.ok()
539+
d.set_item("__annotations__", vm.ctx.new_dict().into(), vm)
540+
.ok()
545541
})
546542
.expect("Failed to initialize __main__.__annotations__");
547543

src/shell/helper.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ impl<'vm> ShellHelper<'vm> {
8585
} else {
8686
// we need to get a variable based off of globals/builtins
8787

88-
let globals = str_iter_method(self.globals.as_object().to_owned(), "keys").ok()?;
89-
let builtins =
90-
str_iter_method(self.vm.builtins.as_object().to_owned(), "__dir__").ok()?;
88+
let globals = str_iter_method(self.globals.clone().into(), "keys").ok()?;
89+
let builtins = str_iter_method(self.vm.builtins.clone().into(), "__dir__").ok()?;
9190
(first, globals, Some(builtins))
9291
};
9392
Some((word_start, iter1.chain(iter2.into_iter().flatten())))

stdlib/src/array.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ mod array {
3333
AsBuffer, AsMapping, Comparable, Constructor, IterNext, IterNextIterable, Iterable,
3434
PyComparisonOp,
3535
},
36-
IdProtocol, PyObject, PyObjectRef, PyObjectView, PyObjectWrap, PyRef, PyResult,
37-
PyValue, TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine,
36+
AsPyObject, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue,
37+
TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine,
3838
},
3939
};
4040
use itertools::Itertools;
4141
use num_traits::ToPrimitive;
42-
use std::cmp::Ordering;
43-
use std::{fmt, os::raw};
42+
use std::{cmp::Ordering, fmt, os::raw};
4443

4544
macro_rules! def_array_enum {
4645
($(($n:ident, $t:ty, $c:literal, $scode:literal)),*$(,)?) => {

stdlib/src/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod _json {
99
function::{IntoPyObject, IntoPyResult, OptionalArg},
1010
protocol::PyIterReturn,
1111
types::{Callable, Constructor},
12-
IdProtocol, PyObjectRef, PyObjectView, PyResult, PyValue, VirtualMachine,
12+
AsPyObject, PyObjectRef, PyObjectView, PyResult, PyValue, VirtualMachine,
1313
};
1414
use num_bigint::BigInt;
1515
use std::str::FromStr;

vm/src/builtins/asyncgenerator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
protocol::PyIterReturn,
88
pyclass::PyClassImpl,
99
types::{Constructor, IterNext, IterNextIterable, Unconstructible},
10-
IdProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
10+
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
1111
};
1212

1313
use crossbeam_utils::atomic::AtomicCell;

vm/src/builtins/bytearray.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::{
3333
IterNextIterable, Iterable, PyComparisonOp, Unconstructible, Unhashable,
3434
},
3535
utils::Either,
36-
IdProtocol, PyContext, PyObject, PyObjectRef, PyObjectView, PyObjectWrap, PyRef, PyResult,
36+
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyObjectWrap, PyRef, PyResult,
3737
PyValue, TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine,
3838
};
3939
use bstr::ByteSlice;

vm/src/builtins/bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
IterNextIterable, Iterable, PyComparisonOp, Unconstructible,
2323
},
2424
utils::Either,
25-
IdProtocol, PyContext, PyObject, PyObjectRef, PyObjectView, PyObjectWrap, PyRef, PyResult,
25+
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyObjectWrap, PyRef, PyResult,
2626
PyValue, TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine,
2727
};
2828
use bstr::ByteSlice;

vm/src/builtins/code.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
bytecode::{self, BorrowedConstant, Constant, ConstantBag},
88
function::FuncArgs,
99
pyclass::{PyClassImpl, StaticType},
10-
IdProtocol, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
10+
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
1111
VirtualMachine,
1212
};
1313
use num_traits::Zero;

vm/src/builtins/complex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
},
88
pyclass::PyClassImpl,
99
types::{Comparable, Constructor, Hashable, PyComparisonOp},
10-
IdProtocol, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
10+
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
1111
VirtualMachine,
1212
};
1313
use num_complex::Complex64;

vm/src/builtins/coroutine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
protocol::PyIterReturn,
77
pyclass::PyClassImpl,
88
types::{Constructor, IterNext, IterNextIterable, Unconstructible},
9-
IdProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
9+
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
1010
};
1111

1212
#[pyclass(module = false, name = "coroutine")]

0 commit comments

Comments
 (0)