merge TypeProtocol in AsPyObject

This commit is contained in:
Jeong Yunwon committed 2022-04-17 19:26:10 +09:00
1 parent 7f9e8254c4
commit aa76a34963
86 files changed
+127 -164

No files matched your search

+1 -1
View File
@@ -52,7 +52,7 @@ use rustpython_vm::{
scope::Scope,
stdlib::{atexit, sys},
AsPyObject, InitParameter, Interpreter, PyObjectRef, PyResult, PySettings, TryFromObject,
TypeProtocol, VirtualMachine,
VirtualMachine,
};
use std::{env, path::Path, process, str::FromStr};
+1 -1
View File
@@ -6,7 +6,7 @@ use rustpython_vm::{
builtins::PyBaseExceptionRef,
compile::{self, CompileError, CompileErrorType},
scope::Scope,
PyResult, TypeProtocol, VirtualMachine,
AsPyObject, PyResult, VirtualMachine,
};
enum ShellExecResult {
+1 -1
View File
@@ -34,7 +34,7 @@ mod array {
PyComparisonOp,
},
AsPyObject, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue,
TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine,
TryFromBorrowedObject, TryFromObject, VirtualMachine,
},
};
use itertools::Itertools;
+1 -1
View File
@@ -16,7 +16,7 @@ mod _csv {
match_class,
protocol::{PyIter, PyIterReturn},
types::{IterNext, IterNextIterable},
PyObjectRef, PyObjectView, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
AsPyObject, PyObjectRef, PyObjectView, PyResult, PyValue, TryFromObject, VirtualMachine,
};
use itertools::{self, Itertools};
use std::fmt;
+1 -1
View File
@@ -6,7 +6,7 @@ mod math {
builtins::{try_bigint_to_f64, try_f64_to_bigint, PyFloat, PyInt, PyIntRef},
function::{ArgIntoFloat, ArgIterable, OptionalArg, PosArgs},
utils::Either,
PyObject, PyObjectRef, PyRef, PyResult, TypeProtocol, VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyRef, PyResult, VirtualMachine,
};
use num_bigint::BigInt;
use num_traits::{One, Signed, Zero};
+1 -1
View File
@@ -16,7 +16,7 @@ pub(crate) mod _struct {
match_class,
protocol::PyIterReturn,
types::{Constructor, IterNext, IterNextIterable},
PyObjectRef, PyObjectView, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
AsPyObject, PyObjectRef, PyObjectView, PyResult, PyValue, TryFromObject, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
+1 -1
View File
@@ -266,7 +266,7 @@ mod decl {
common::lock::PyMutex,
function::{IntoPyObject, OptionalArg},
stdlib::io::Fildes,
PyValue, TypeProtocol,
AsPyObject, PyValue,
};
use libc::pollfd;
use num_traits::ToPrimitive;
+1 -1
View File
@@ -18,7 +18,7 @@ mod _socket {
OptionalOption,
},
utils::{Either, ToCString},
PyObjectRef, PyResult, PyValue, TryFromBorrowedObject, TryFromObject, TypeProtocol,
AsPyObject, PyObjectRef, PyResult, PyValue, TryFromBorrowedObject, TryFromObject,
VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::{
cformat::CFormatString,
function::{single_or_tuple_any, OptionalOption},
protocol::PyIterIter,
PyObjectRef, PyResult, TryFromObject, TypeProtocol, VirtualMachine,
AsPyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine,
};
use num_traits::{cast::ToPrimitive, sign::Signed};
use std::str::FromStr;
+1 -1
View File
@@ -7,7 +7,7 @@ use crate::{
protocol::PyIterReturn,
pyclass::PyClassImpl,
types::{Constructor, IterNext, IterNextIterable, Unconstructible},
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
+1 -1
View File
@@ -4,7 +4,7 @@ use crate::{
function::{FuncArgs, IntoPyNativeFunc, PyNativeFunc},
pyclass::PyClassImpl,
types::{Callable, Constructor, GetDescriptor, Unconstructible},
PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
use std::fmt;
+1 -1
View File
@@ -34,7 +34,7 @@ use crate::{
},
utils::Either,
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyObjectWrap, PyRef, PyResult,
PyValue, TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine,
PyValue, TryFromBorrowedObject, TryFromObject, VirtualMachine,
};
use bstr::ByteSlice;
use std::{borrow::Cow, mem::size_of};
+1 -1
View File
@@ -23,7 +23,7 @@ use crate::{
},
utils::Either,
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyObjectWrap, PyRef, PyResult,
PyValue, TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine,
PyValue, TryFromBorrowedObject, TryFromObject, VirtualMachine,
};
use bstr::ByteSlice;
use std::{borrow::Cow, mem::size_of, ops::Deref};
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::{
builtins::PyBoundMethod,
pyclass::PyClassImpl,
types::{Constructor, GetDescriptor},
PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
/// classmethod(function) -> method
+1 -2
View File
@@ -7,8 +7,7 @@ use crate::{
bytecode::{self, BorrowedConstant, Constant, ConstantBag},
function::FuncArgs,
pyclass::{PyClassImpl, StaticType},
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
VirtualMachine,
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
use num_traits::Zero;
use std::{fmt, ops::Deref};
+1 -2
View File
@@ -7,8 +7,7 @@ use crate::{
},
pyclass::PyClassImpl,
types::{Comparable, Constructor, Hashable, PyComparisonOp},
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
VirtualMachine,
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
use num_complex::Complex64;
use num_traits::Zero;
+1 -1
View File
@@ -22,7 +22,7 @@ use crate::{
},
vm::{ReprGuard, VirtualMachine},
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue,
TryFromObject, TypeProtocol,
TryFromObject,
};
use rustpython_common::lock::PyMutex;
use std::{borrow::Cow, fmt};
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::{
protocol::{PyIter, PyIterReturn},
pyclass::PyClassImpl,
types::{Constructor, IterNext, IterNextIterable},
PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
use num_bigint::BigInt;
use num_traits::Zero;
+1 -1
View File
@@ -10,7 +10,7 @@ use crate::{
pyclass::PyClassImpl,
types::{Comparable, Constructor, Hashable, PyComparisonOp},
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromBorrowedObject,
TryFromObject, TypeProtocol, VirtualMachine,
TryFromObject, VirtualMachine,
};
use num_bigint::{BigInt, ToBigInt};
use num_complex::Complex64;
+1 -2
View File
@@ -14,8 +14,7 @@ use crate::{
pyclass::PyClassImpl,
scope::Scope,
types::{Callable, Comparable, Constructor, GetAttr, GetDescriptor, PyComparisonOp},
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
VirtualMachine,
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
#[cfg(feature = "jit")]
use crate::{common::lock::OnceCell, function::IntoPyObject};
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::{
builtins::{float, int, pybool, PyBaseExceptionRef, PyDictRef, PyFunction, PyStrRef},
bytecode::CodeFlags,
function::{FuncArgs, IntoPyObject},
AsPyObject, PyObject, PyObjectRef, PyResult, TryFromObject, TypeProtocol, VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine,
};
use num_traits::ToPrimitive;
use rustpython_jit::{AbiValue, Args, CompiledCode, JitArgumentError, JitType};
+1 -1
View File
@@ -6,7 +6,7 @@ use crate::{
pyclass::PyClassImpl,
types::{AsMapping, Callable, Comparable, Constructor, GetAttr, Hashable, PyComparisonOp},
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue,
TryFromObject, TypeProtocol, VirtualMachine,
TryFromObject, VirtualMachine,
};
use std::fmt;
+1 -1
View File
@@ -7,7 +7,7 @@ use crate::{
pyclass::PyClassImpl,
pyobject::PyThreadingConstraint,
types::{Constructor, GetDescriptor, Unconstructible},
PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
pub type PyGetterFunc = Box<py_dyn_fn!(dyn Fn(&VirtualMachine, PyObjectRef) -> PyResult)>;
+1 -1
View File
@@ -10,7 +10,7 @@ use crate::{
pyclass::PyClassImpl,
types::{Comparable, Constructor, Hashable, PyComparisonOp},
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromBorrowedObject,
TypeProtocol, VirtualMachine,
VirtualMachine,
};
use bstr::ByteSlice;
use num_bigint::{BigInt, BigUint, Sign};
+1 -1
View File
@@ -16,7 +16,7 @@ use crate::{
utils::collection_repr,
vm::{ReprGuard, VirtualMachine},
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyObjectWrap, PyRef, PyResult,
PyValue, TypeProtocol,
PyValue,
};
use std::{borrow::Cow, fmt, ops::DerefMut};
+1 -1
View File
@@ -6,7 +6,7 @@ use crate::{
protocol::{PyMapping, PyMappingMethods, PySequence, PySequenceMethods},
pyclass::PyClassImpl,
types::{AsMapping, AsSequence, Constructor, Iterable},
PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
VirtualMachine,
};
+1 -1
View File
@@ -19,7 +19,7 @@ use crate::{
types::{AsBuffer, AsMapping, AsSequence, Comparable, Constructor, Hashable, PyComparisonOp},
utils::Either,
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyObjectWrap, PyRef, PyResult,
PyValue, TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine,
PyValue, TryFromBorrowedObject, TryFromObject, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use itertools::Itertools;
+1 -1
View File
@@ -42,7 +42,7 @@ impl PyModule {
#[pymethod(magic)]
fn init(zelf: PyRef<Self>, args: ModuleInitArgs, vm: &VirtualMachine) {
debug_assert!(crate::TypeProtocol::class(zelf.as_object())
debug_assert!(crate::AsPyObject::class(zelf.as_object())
.slots
.flags
.has_feature(crate::types::PyTypeFlags::HAS_DICT));
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::{
pyclass::PyClassImpl,
types::{Comparable, Constructor, PyComparisonOp},
vm::ReprGuard,
AsPyObject, PyContext, PyObject, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
AsPyObject, PyContext, PyObject, PyRef, PyResult, PyValue, VirtualMachine,
};
/// A simple attribute-based namespace.
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::{
pyclass::PyClassImpl,
types::PyComparisonOp,
utils::Either,
AsPyObject, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
AsPyObject, PyContext, PyObject, PyObjectRef, PyResult, PyValue, VirtualMachine,
};
/// object()
+5 -5
View File
@@ -4,8 +4,8 @@
use super::PyTypeRef;
use crate::common::lock::PyRwLock;
use crate::{
function::FuncArgs, pyclass::PyClassImpl, types::GetDescriptor, PyContext, PyObjectRef, PyRef,
PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
function::FuncArgs, pyclass::PyClassImpl, types::GetDescriptor, AsPyObject, PyContext,
PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
/// Property attribute.
@@ -185,7 +185,7 @@ impl PyProperty {
deleter: PyRwLock::new(zelf.fdel()),
doc: PyRwLock::new(None),
}
.into_ref_with_type(vm, TypeProtocol::clone_class(&zelf))
.into_ref_with_type(vm, AsPyObject::clone_class(&zelf))
}
#[pymethod]
@@ -200,7 +200,7 @@ impl PyProperty {
deleter: PyRwLock::new(zelf.fdel()),
doc: PyRwLock::new(None),
}
.into_ref_with_type(vm, TypeProtocol::clone_class(&zelf))
.into_ref_with_type(vm, AsPyObject::clone_class(&zelf))
}
#[pymethod]
@@ -215,7 +215,7 @@ impl PyProperty {
deleter: PyRwLock::new(deleter.or_else(|| zelf.fdel())),
doc: PyRwLock::new(None),
}
.into_ref_with_type(vm, TypeProtocol::clone_class(&zelf))
.into_ref_with_type(vm, AsPyObject::clone_class(&zelf))
}
#[pyproperty(magic)]
+1 -1
View File
@@ -4,7 +4,7 @@ use crate::{
pyclass::PyClassImpl,
types::Constructor,
AsPyObject, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromBorrowedObject,
TypeProtocol, VirtualMachine,
VirtualMachine,
};
use num_bigint::Sign;
use num_traits::Zero;
+1 -1
View File
@@ -19,7 +19,7 @@ use crate::{
Iterable, PyComparisonOp, Unconstructible,
},
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue,
TryFromBorrowedObject, TypeProtocol, VirtualMachine,
TryFromBorrowedObject, VirtualMachine,
};
use ascii::{AsciiStr, AsciiString};
use bstr::ByteSlice;
+1 -1
View File
@@ -8,7 +8,7 @@ use crate::{
function::OptionalArg,
pyclass::PyClassImpl,
types::{Constructor, GetAttr, GetDescriptor},
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
#[pyclass(module = false, name = "super")]
+1 -2
View File
@@ -12,8 +12,7 @@ use crate::{
pyclass::{PyClassImpl, StaticType},
pyobject::PyLease,
types::{Callable, GetAttr, PyTypeFlags, PyTypeSlots, SetAttr},
AsPyObject, PyContext, PyObjectRef, PyObjectWeak, PyRef, PyResult, PyValue, TypeProtocol,
VirtualMachine,
AsPyObject, PyContext, PyObjectRef, PyObjectWeak, PyRef, PyResult, PyValue, VirtualMachine,
};
use itertools::Itertools;
use std::{
+1 -1
View File
@@ -7,7 +7,7 @@ use crate::{
pyclass::PyClassImpl,
types::{AsMapping, Comparable, GetAttr, Hashable, Iterable, PyComparisonOp},
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue,
TryFromObject, TypeProtocol, VirtualMachine,
TryFromObject, VirtualMachine,
};
use std::fmt;
+1 -1
View File
@@ -10,7 +10,7 @@ use crate::{
Iterable, PyComparisonOp, Unconstructible,
},
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue,
TryFromObject, TypeProtocol, VirtualMachine,
TryFromObject, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use num_bigint::{BigInt, Sign};
-1
View File
@@ -18,7 +18,6 @@ use crate::{
utils::collection_repr,
vm::{ReprGuard, VirtualMachine},
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
TypeProtocol,
};
use std::borrow::Cow;
use std::{fmt, ops::Deref};
+2 -2
View File
@@ -1,7 +1,7 @@
use super::PyTypeRef;
use crate::{
function::IntoPyObject, pyclass::PyClassImpl, types::Constructor, PyContext, PyObjectRef,
PyResult, PyValue, TypeProtocol, VirtualMachine,
function::IntoPyObject, pyclass::PyClassImpl, types::Constructor, AsPyObject, PyContext,
PyObjectRef, PyResult, PyValue, VirtualMachine,
};
#[pyclass(module = false, name = "NoneType")]
+1 -2
View File
@@ -4,8 +4,7 @@ use crate::{
function::{FuncArgs, IntoPyObject, OptionalArg, PyComparisonValue},
pyclass::PyClassImpl,
types::{Comparable, Constructor, Hashable, PyComparisonOp, Unhashable},
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
VirtualMachine,
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
use num_bigint::{BigInt, ToBigInt};
use num_traits::{One, Signed, ToPrimitive, Zero};
-1
View File
@@ -15,7 +15,6 @@ use crate::{
utils::collection_repr,
vm::{ReprGuard, VirtualMachine},
AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
TypeProtocol,
};
use std::{borrow::Cow, fmt, marker::PhantomData};
+1 -1
View File
@@ -8,7 +8,7 @@ use crate::{
pyclass::PyClassImpl,
types::{Callable, Comparable, Constructor, Hashable, PyComparisonOp},
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectWrap, PyRef, PyResult, PyValue,
TypeProtocol, VirtualMachine,
VirtualMachine,
};
pub use crate::pyobject::PyWeak;
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::{
protocol::{PyIter, PyIterReturn},
pyclass::PyClassImpl,
types::{Constructor, IterNext, IterNextIterable},
PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
use rustpython_common::atomic::{self, PyAtomic, Radium};
+1 -1
View File
@@ -7,7 +7,7 @@ use crate::{
function::ArgIntoFloat,
protocol::PyBuffer,
stdlib::builtins,
PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine,
AsPyObject, PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine,
};
use itertools::Itertools;
use num_bigint::{BigInt, Sign};
+1 -2
View File
@@ -2,8 +2,7 @@ use crate::{
builtins::{PyBaseExceptionRef, PyBytesRef, PyStr, PyStrRef, PyTuple, PyTupleRef},
common::{ascii, lock::PyRwLock},
function::IntoPyObject,
AsPyObject, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol,
VirtualMachine,
AsPyObject, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
use std::{borrow::Cow, collections::HashMap, fmt::Write, ops::Range};
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::{
pyobject::{PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol},
pyobject::{AsPyObject, PyObject, PyObjectRef, PyRef, PyResult, PyValue},
vm::VirtualMachine,
};
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::{
common::lock::PyMutex,
frame::{ExecutionResult, FrameRef},
protocol::PyIterReturn,
AsPyObject, PyObject, PyObjectRef, PyResult, TypeProtocol, VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyResult, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
+1 -2
View File
@@ -10,8 +10,7 @@ use crate::common::{
use crate::{
builtins::{PyInt, PyStr, PyStrRef},
function::IntoPyObject,
AsPyObject, PyObject, PyObjectRef, PyObjectWrap, PyRefExact, PyResult, TypeProtocol,
VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyObjectWrap, PyRefExact, PyResult, VirtualMachine,
};
use num_traits::ToPrimitive;
use std::{fmt, mem::size_of, ops::ControlFlow};
+1 -2
View File
@@ -9,8 +9,7 @@ use crate::{
pyclass::{PyClassImpl, StaticType},
stdlib::sys,
suggestion::offer_suggestions,
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
VirtualMachine,
AsPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use itertools::Itertools;
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::{
common::float_ops,
function::{FuncArgs, IntoPyException},
stdlib::builtins,
PyObject, PyObjectRef, PyResult, TypeProtocol, VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyResult, VirtualMachine,
};
use itertools::{Itertools, PeekingNext};
use num_bigint::{BigInt, Sign};
+1 -1
View File
@@ -16,7 +16,7 @@ use crate::{
stdlib::builtins,
types::PyComparisonOp,
AsPyObject, PyMethod, PyObject, PyObjectRef, PyObjectWrap, PyRef, PyResult, PyValue,
TryFromObject, TypeProtocol, VirtualMachine,
TryFromObject, VirtualMachine,
};
use indexmap::IndexMap;
use itertools::Itertools;
+1 -1
View File
@@ -6,7 +6,7 @@ mod number;
use crate::{
builtins::{PyBaseExceptionRef, PyTupleRef, PyTypeRef},
pyobject::PyThreadingConstraint,
PyObject, PyObjectPayload, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
AsPyObject, PyObject, PyObjectPayload, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
VirtualMachine,
};
use indexmap::IndexMap;
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::{
builtins::{iter::PySequenceIterator, PyDict, PyDictRef},
protocol::PyIter,
protocol::{PyIterIter, PyMapping, PyMappingMethods},
PyObject, PyObjectRef, PyObjectWrap, PyResult, PyValue, TryFromObject, TypeProtocol,
AsPyObject, PyObject, PyObjectRef, PyObjectWrap, PyResult, PyValue, TryFromObject,
VirtualMachine,
};
use std::{borrow::Borrow, marker::PhantomData};
+1 -1
View File
@@ -1,4 +1,4 @@
use crate::{PyObjectRef, PyResult, TryFromObject, TypeProtocol, VirtualMachine};
use crate::{AsPyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine};
use num_complex::Complex64;
/// A Python complex-like object.
+1 -1
View File
@@ -8,7 +8,7 @@ use crate::{
scope::Scope,
version::get_git_revision,
vm::{InitParameter, VirtualMachine},
PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
AsPyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
};
use rand::Rng;
+3 -5
View File
@@ -89,13 +89,11 @@ mod pyobject {
pub use self::convert::{TryFromBorrowedObject, TryFromObject};
// pyobject items
pub use self::pyobject::{
PyContext, PyMethod, PyObjectPayload, PyObjectWrap, PyRefExact, PyResult, PyStructSequence,
PyValue, TypeProtocol,
AsPyObject, PyContext, PyMethod, PyObjectPayload, PyObjectWrap, PyRefExact, PyResult,
PyStructSequence, PyValue,
};
// pyobjectrc items
pub use self::pyobject::{
AsPyObject, PyObject, PyObjectRef, PyObjectView, PyObjectWeak, PyRef, PyWeakRef,
};
pub use self::pyobject::{PyObject, PyObjectRef, PyObjectView, PyObjectWeak, PyRef, PyWeakRef};
pub use self::vm::{InitParameter, Interpreter, PySettings, VirtualMachine};
pub use rustpython_bytecode as bytecode;
pub use rustpython_common as common;
+2 -2
View File
@@ -8,8 +8,8 @@ use crate::{
},
sliceable::wrap_index,
types::{Constructor, Unconstructible},
PyObject, PyObjectPayload, PyObjectRef, PyObjectView, PyObjectWrap, PyRef, PyResult, PyValue,
TryFromBorrowedObject, TypeProtocol, VirtualMachine,
AsPyObject, PyObject, PyObjectPayload, PyObjectRef, PyObjectView, PyObjectWrap, PyRef,
PyResult, PyValue, TryFromBorrowedObject, VirtualMachine,
};
use itertools::Itertools;
use std::{borrow::Cow, fmt::Debug, ops::Range};
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::{
builtins::iter::PySequenceIterator,
function::{IntoPyObject, IntoPyResult},
AsPyObject, PyObject, PyObjectRef, PyObjectWrap, PyResult, PyValue, TryFromObject,
TypeProtocol, VirtualMachine,
VirtualMachine,
};
use std::borrow::Borrow;
use std::ops::Deref;
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::{
},
common::lock::OnceCell,
function::IntoPyResult,
AsPyObject, PyObject, PyObjectRef, PyResult, TypeProtocol, VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyResult, VirtualMachine,
};
// Mapping protocol
+1 -1
View File
@@ -13,7 +13,7 @@ use crate::{
protocol::{PyIter, PyMapping, PySequence},
types::{Constructor, PyComparisonOp},
utils::Either,
AsPyObject, PyObject, PyObjectRef, PyResult, TryFromObject, TypeProtocol, VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine,
};
// RustPython doesn't need these items
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::{
common::lock::OnceCell,
function::{IntoPyObject, PyArithmeticValue},
protocol::PyMapping,
AsPyObject, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyResult, PyValue, VirtualMachine,
};
use itertools::Itertools;
use std::{
+1 -1
View File
@@ -4,7 +4,7 @@ use serde::de::{DeserializeSeed, Visitor};
use serde::ser::{Serialize, SerializeMap, SerializeSeq};
use crate::builtins::{dict::PyDictRef, float, int, list::PyList, pybool, tuple::PyTuple, PyStr};
use crate::{PyObject, PyObjectRef, TypeProtocol, VirtualMachine};
use crate::{AsPyObject, PyObject, PyObjectRef, VirtualMachine};
#[inline]
pub fn serialize<S>(
+31 -51
View File
@@ -416,6 +416,30 @@ where
{
self.get_id() == other.get_id()
}
#[inline(always)]
fn class(&self) -> PyLease<'_, PyType> {
self.as_object().lease_class()
}
fn clone_class(&self) -> PyTypeRef {
PyLease::into_pyref(self.class())
}
fn get_class_attr(&self, attr_name: &str) -> Option<PyObjectRef> {
self.class().get_attr(attr_name)
}
fn has_class_attr(&self, attr_name: &str) -> bool {
self.class().has_attr(attr_name)
}
/// Determines if `obj` actually an instance of `cls`, this doesn't call __instancecheck__, so only
/// use this if `cls` is known to have not overridden the base __instancecheck__ magic method.
#[inline]
fn isinstance(&self, cls: &PyObjectView<PyType>) -> bool {
self.class().issubclass(cls)
}
}
impl<T> AsPyObject for T where T: Borrow<PyObject> {}
@@ -425,6 +449,13 @@ impl PyObject {
fn _get_id(&self) -> usize {
self as *const PyObject as usize
}
#[inline]
fn lease_class(&self) -> PyLease<'_, PyType> {
PyLease {
inner: self.class_lock().read(),
}
}
}
// impl<T: ?Sized> Borrow<PyObject> for PyRc<T> {
@@ -473,57 +504,6 @@ where
}
}
pub trait TypeProtocol: AsPyObject {
fn class(&self) -> PyLease<'_, PyType>;
fn clone_class(&self) -> PyTypeRef {
PyLease::into_pyref(self.class())
}
fn get_class_attr(&self, attr_name: &str) -> Option<PyObjectRef> {
self.class().get_attr(attr_name)
}
fn has_class_attr(&self, attr_name: &str) -> bool {
self.class().has_attr(attr_name)
}
/// Determines if `obj` actually an instance of `cls`, this doesn't call __instancecheck__, so only
/// use this if `cls` is known to have not overridden the base __instancecheck__ magic method.
#[inline]
fn isinstance(&self, cls: &PyObjectView<PyType>) -> bool {
self.class().issubclass(cls)
}
}
impl TypeProtocol for PyObjectRef {
fn class(&self) -> PyLease<'_, PyType> {
PyLease {
inner: self.class_lock().read(),
}
}
}
impl TypeProtocol for PyObject {
fn class(&self) -> PyLease<'_, PyType> {
PyLease {
inner: self.class_lock().read(),
}
}
}
impl<T: PyObjectPayload> TypeProtocol for PyObjectView<T> {
fn class(&self) -> PyLease<'_, PyType> {
self.as_object().class()
}
}
impl<T: PyObjectPayload> TypeProtocol for PyRef<T> {
fn class(&self) -> PyLease<'_, PyType> {
self.as_object().class()
}
}
impl<T, P> IntoPyRef<P> for T
where
P: PyValue + IntoPyObject + From<T>,
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::common::linked_list::{Link, LinkedList, Pointers};
use crate::common::lock::{PyMutex, PyMutexGuard, PyRwLock};
use crate::common::refcount::RefCount;
use crate::{
_pyobject::{AsPyObject, PyObjectPayload, PyObjectWrap, PyResult, TypeProtocol},
_pyobject::{AsPyObject, PyObjectPayload, PyObjectWrap, PyResult},
builtins::{PyBaseExceptionRef, PyDictRef, PyTypeRef},
vm::VirtualMachine,
};
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::{
types::{richcompare_wrapper, PyComparisonOp, RichCompareFunc},
utils::Either,
vm::VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyResult, TypeProtocol,
AsPyObject, PyObject, PyObjectRef, PyResult,
};
use itertools::Itertools;
use optional::Optioned;
+1 -1
View File
@@ -7,7 +7,7 @@ use crate::{
int::PyInt,
slice::{PySlice, SaturatedSliceIter},
},
PyObject, PyResult, TryFromBorrowedObject, TypeProtocol, VirtualMachine,
AsPyObject, PyObject, PyResult, TryFromBorrowedObject, VirtualMachine,
};
pub trait SliceableSequenceMutOp {
+2 -3
View File
@@ -8,8 +8,7 @@ mod gen;
use crate::{
builtins::{self, PyStrRef, PyTypeRef},
pyclass::{PyClassImpl, StaticType},
AsPyObject, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol,
VirtualMachine,
AsPyObject, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
use num_complex::Complex64;
use num_traits::{ToPrimitive, Zero};
@@ -22,7 +21,7 @@ use rustpython_parser::parser;
#[pymodule]
mod _ast {
use crate::{
builtins::PyStrRef, function::FuncArgs, PyObjectRef, PyResult, PyValue, TypeProtocol,
builtins::PyStrRef, function::FuncArgs, AsPyObject, PyObjectRef, PyResult, PyValue,
VirtualMachine,
};
#[pyattr]
+1 -1
View File
@@ -3,7 +3,7 @@ pub(crate) use atexit::make_module;
#[pymodule]
mod atexit {
use crate::{function::FuncArgs, PyObjectRef, PyResult, TypeProtocol, VirtualMachine};
use crate::{function::FuncArgs, AsPyObject, PyObjectRef, PyResult, VirtualMachine};
#[pyfunction]
fn register(func: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyObjectRef {
+1 -1
View File
@@ -34,7 +34,7 @@ mod builtins {
types::PyComparisonOp,
utils::Either,
AsPyObject, PyObject, PyObjectRef, PyObjectWrap, PyRef, PyResult, PyValue, TryFromObject,
TypeProtocol, VirtualMachine,
VirtualMachine,
};
use num_traits::{Signed, ToPrimitive, Zero};
+1 -1
View File
@@ -19,7 +19,7 @@ mod _collections {
},
utils::collection_repr,
vm::ReprGuard,
AsPyObject, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use std::cmp::max;
+2 -3
View File
@@ -89,7 +89,7 @@ mod _io {
utils::Either,
vm::{ReprGuard, VirtualMachine},
AsPyObject, PyContext, PyObject, PyObjectRef, PyObjectWrap, PyRef, PyResult, PyValue,
TryFromBorrowedObject, TryFromObject, TypeProtocol,
TryFromBorrowedObject, TryFromObject,
};
use bstr::ByteSlice;
use crossbeam_utils::atomic::AtomicCell;
@@ -3661,8 +3661,7 @@ mod fileio {
ArgBytesLike, ArgMemoryBuffer, FuncArgs, IntoPyException, OptionalArg, OptionalOption,
},
stdlib::os,
AsPyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
VirtualMachine,
AsPyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use std::io::{Read, Write};
+1 -2
View File
@@ -12,8 +12,7 @@ mod decl {
protocol::{PyIter, PyIterReturn},
stdlib::sys,
types::{Constructor, IterNext, IterNextIterable},
AsPyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, PyWeakRef, TypeProtocol,
VirtualMachine,
AsPyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, PyWeakRef, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use num_bigint::BigInt;
+1 -1
View File
@@ -10,7 +10,7 @@ mod decl {
bytecode,
function::{ArgBytesLike, IntoPyObject},
protocol::PyBuffer,
pyobject::{AsPyObject, TypeProtocol},
pyobject::AsPyObject,
PyObjectRef, PyResult, TryFromObject, VirtualMachine,
};
/// TODO
+1 -2
View File
@@ -20,8 +20,7 @@ mod _operator {
},
utils::Either,
vm::ReprGuard,
AsPyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, TypeProtocol,
VirtualMachine,
AsPyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, VirtualMachine,
};
/// Same as a < b.
+2 -2
View File
@@ -4,7 +4,7 @@ use crate::{
function::{ArgumentError, FromArgs, FuncArgs, IntoPyException, IntoPyObject},
protocol::PyBuffer,
AsPyObject, PyObject, PyObjectRef, PyResult, PyValue, TryFromBorrowedObject, TryFromObject,
TypeProtocol, VirtualMachine,
VirtualMachine,
};
use std::{
ffi, fs,
@@ -440,7 +440,7 @@ pub(super) mod _os {
types::{IterNext, IterNextIterable},
utils::Either,
vm::{ReprGuard, VirtualMachine},
PyObjectRef, PyRef, PyResult, PyStructSequence, PyValue, TryFromObject, TypeProtocol,
AsPyObject, PyObjectRef, PyRef, PyResult, PyStructSequence, PyValue, TryFromObject,
};
use crossbeam_utils::atomic::AtomicCell;
use itertools::Itertools;
+2 -2
View File
@@ -37,7 +37,7 @@ pub mod module {
},
types::Constructor,
utils::{Either, ToCString},
PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
AsPyObject, PyObjectRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
use bitflags::bitflags;
use nix::{
@@ -557,7 +557,7 @@ pub mod module {
target_os = "android"
))]
fn try_to_libc(&self, vm: &VirtualMachine) -> PyResult<libc::sched_param> {
use crate::TypeProtocol;
use crate::AsPyObject;
let priority_class = self.sched_priority.class();
let priority_type = priority_class.name();
let priority = self.sched_priority.clone();
+1 -1
View File
@@ -10,7 +10,7 @@ pub(crate) mod _thread {
py_io,
types::{Constructor, GetAttr, SetAttr},
utils::Either,
AsPyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
AsPyObject, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
use parking_lot::{
lock_api::{RawMutex as RawMutexT, RawMutexTimed, RawReentrantMutex},
+1 -1
View File
@@ -5,7 +5,7 @@ mod _warnings {
use crate::{
builtins::{PyStrRef, PyTypeRef},
function::OptionalArg,
PyResult, TypeProtocol, VirtualMachine,
AsPyObject, PyResult, VirtualMachine,
};
#[derive(FromArgs)]
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::{
builtins::{PyStr, PyStrRef},
exceptions::types::PyBaseExceptionRef,
sliceable::SliceableSequenceOp,
AsPyObject, PyObjectRef, PyObjectView, TypeProtocol, VirtualMachine,
AsPyObject, PyObjectRef, PyObjectView, VirtualMachine,
};
use rustpython_common::str::levenshtein::{levenshtein_distance, MOVE_COST};
use std::iter::ExactSizeIterator;
+1 -2
View File
@@ -6,8 +6,7 @@ use crate::{
protocol::{PyBuffer, PyIterReturn, PyMapping, PyMappingMethods},
protocol::{PySequence, PySequenceMethods},
utils::Either,
AsPyObject, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, TypeProtocol,
VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use num_traits::{Signed, ToPrimitive};
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::{
builtins::{PyFloat, PyStr},
function::{IntoPyException, IntoPyObject},
PyObject, PyObjectRef, PyObjectWrap, PyResult, TryFromObject, TypeProtocol, VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyObjectWrap, PyResult, TryFromObject, VirtualMachine,
};
use num_traits::ToPrimitive;
use std::borrow::Borrow;
+2 -2
View File
@@ -25,7 +25,7 @@ use crate::{
pyobject::PyLease,
scope::Scope,
signal, stdlib, AsPyObject, PyContext, PyObject, PyObjectRef, PyRef, PyRefExact, PyResult,
PyValue, TypeProtocol,
PyValue,
};
use crossbeam_utils::atomic::AtomicCell;
use std::{
@@ -67,7 +67,7 @@ struct ExceptionStack {
}
pub(crate) mod thread {
use super::{PyObject, TypeProtocol, VirtualMachine};
use super::{AsPyObject, PyObject, VirtualMachine};
use itertools::Itertools;
use std::{cell::RefCell, ptr::NonNull, thread_local};
+1 -1
View File
@@ -10,7 +10,7 @@ use crate::{
function::IntoPyObject,
scope::Scope,
vm::VirtualMachine,
AsPyObject, PyObject, PyObjectRef, PyObjectWrap, PyRef, TypeProtocol,
AsPyObject, PyObject, PyObjectRef, PyObjectWrap, PyRef,
};
/// Collection of object creation helpers
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::{
builtins::{PyBaseExceptionRef, PyList, PyStr},
function::{FuncArgs, IntoFuncArgs},
vm::VirtualMachine,
AsPyObject, PyMethod, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol,
AsPyObject, PyMethod, PyObject, PyObjectRef, PyResult, PyValue,
};
/// Trace events for sys.settrace and sys.setprofile.
+1 -1
View File
@@ -4,7 +4,7 @@ use crate::{
protocol::PyIterReturn,
types::PyComparisonOp,
vm::VirtualMachine,
AsPyObject, PyMethod, PyObject, PyObjectRef, PyResult, TypeProtocol,
AsPyObject, PyMethod, PyObject, PyObjectRef, PyResult,
};
/// Collection of operators
+1 -1
View File
@@ -7,7 +7,7 @@ use rustpython_vm::{
compile::{CompileError, CompileErrorType},
exceptions,
function::{ArgBytesLike, FuncArgs},
py_serde, PyObjectRef, PyResult, PyValue, TryFromBorrowedObject, TypeProtocol, VirtualMachine,
py_serde, AsPyObject, PyObjectRef, PyResult, PyValue, TryFromBorrowedObject, VirtualMachine,
};
use wasm_bindgen::{closure::Closure, prelude::*, JsCast};