mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Merge pull request #2281 from youknowone/builtins
vm::obj -> vm::builtins and expose types right under builtins rather than each objxxx submodules
This commit is contained in:
112 files changed
+823
-788
No files matched your search
@@ -73,7 +73,7 @@ pub(crate) fn impl_pyimpl(
|
||||
|
||||
fn impl_extend_class(
|
||||
ctx: &::rustpython_vm::pyobject::PyContext,
|
||||
class: &::rustpython_vm::obj::objtype::PyTypeRef,
|
||||
class: &::rustpython_vm::builtins::PyTypeRef,
|
||||
) {
|
||||
#getset_impl
|
||||
#extend_impl
|
||||
@@ -100,7 +100,7 @@ pub(crate) fn impl_pyimpl(
|
||||
parse_quote! {
|
||||
fn __extend_py_class(
|
||||
ctx: &::rustpython_vm::pyobject::PyContext,
|
||||
class: &::rustpython_vm::obj::objtype::PyTypeRef,
|
||||
class: &::rustpython_vm::builtins::PyTypeRef,
|
||||
) {
|
||||
#getset_impl
|
||||
#extend_impl
|
||||
@@ -162,7 +162,7 @@ fn generate_class_def(
|
||||
|
||||
let base_class = if is_pystruct {
|
||||
quote! {
|
||||
fn base_class(ctx: &::rustpython_vm::pyobject::PyContext) -> ::rustpython_vm::obj::objtype::PyTypeRef {
|
||||
fn base_class(ctx: &::rustpython_vm::pyobject::PyContext) -> ::rustpython_vm::builtins::PyTypeRef {
|
||||
ctx.types.tuple_type.clone()
|
||||
}
|
||||
}
|
||||
@@ -502,7 +502,7 @@ impl ToTokens for GetSetNursery {
|
||||
class.set_str_attr(
|
||||
#name,
|
||||
::rustpython_vm::pyobject::PyObject::new(
|
||||
::rustpython_vm::obj::objgetset::PyGetSet::#constructor(#name.into(), &Self::#getter #setter),
|
||||
::rustpython_vm::builtins::getset::PyGetSet::#constructor(#name.into(), &Self::#getter #setter),
|
||||
ctx.types.getset_type.clone(), None)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ pub(crate) fn impl_pystruct_sequence(
|
||||
let ret = quote! {
|
||||
impl ::rustpython_vm::pyobject::PyStructSequence for #ty {
|
||||
const FIELD_NAMES: &'static [&'static str] = &[#(stringify!(#field_names)),*];
|
||||
fn into_tuple(self, vm: &::rustpython_vm::VirtualMachine) -> ::rustpython_vm::obj::objtuple::PyTuple {
|
||||
fn into_tuple(self, vm: &::rustpython_vm::VirtualMachine) -> ::rustpython_vm::builtins::tuple::PyTuple {
|
||||
let items = vec![#(::rustpython_vm::pyobject::IntoPyObject::into_pyobject(
|
||||
self.#field_names,
|
||||
vm,
|
||||
)),*];
|
||||
::rustpython_vm::obj::objtuple::PyTuple::_new(items.into_boxed_slice())
|
||||
::rustpython_vm::builtins::tuple::PyTuple::_new(items.into_boxed_slice())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -34,7 +34,7 @@ macro_rules! add_python_function {
|
||||
$scope.globals.set_item(
|
||||
def.obj_name.as_str(),
|
||||
$vm.ctx.new_pyfunction(
|
||||
vm::obj::objcode::PyCode::new(*def.clone()).into_ref(&$vm),
|
||||
vm::builtins::PyCode::new(*def.clone()).into_ref(&$vm),
|
||||
$scope.clone(),
|
||||
None,
|
||||
None,
|
||||
|
||||
+2
-2
@@ -7,9 +7,9 @@ extern crate log;
|
||||
use clap::{App, AppSettings, Arg, ArgMatches};
|
||||
use rustpython_compiler::compile;
|
||||
use rustpython_vm::{
|
||||
builtins::{isinstance, PyInt},
|
||||
exceptions::print_exception,
|
||||
match_class,
|
||||
obj::{objint::PyInt, objtype},
|
||||
pyobject::{BorrowValue, ItemProtocol, PyResult},
|
||||
scope::Scope,
|
||||
util, InitParameter, Interpreter, PySettings, VirtualMachine,
|
||||
@@ -67,7 +67,7 @@ fn main() {
|
||||
// See if any exception leaked out:
|
||||
let exitcode = match res {
|
||||
Ok(()) => 0,
|
||||
Err(err) if objtype::isinstance(&err, &vm.ctx.exceptions.system_exit) => {
|
||||
Err(err) if isinstance(&err, &vm.ctx.exceptions.system_exit) => {
|
||||
let args = err.args();
|
||||
match args.borrow_value().len() {
|
||||
0 => 0,
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ use rustpython_compiler::{compile, error::CompileError, error::CompileErrorType}
|
||||
use rustpython_parser::error::{LexicalErrorType, ParseErrorType};
|
||||
use rustpython_vm::readline::{Readline, ReadlineResult};
|
||||
use rustpython_vm::{
|
||||
builtins::isinstance,
|
||||
exceptions::{print_exception, PyBaseExceptionRef},
|
||||
obj::objtype,
|
||||
pyobject::{BorrowValue, PyResult},
|
||||
scope::Scope,
|
||||
VirtualMachine,
|
||||
@@ -127,7 +127,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
|
||||
};
|
||||
|
||||
if let Err(exc) = result {
|
||||
if objtype::isinstance(&exc, &vm.ctx.exceptions.system_exit) {
|
||||
if isinstance(&exc, &vm.ctx.exceptions.system_exit) {
|
||||
repl.save_history(&repl_history_path).unwrap();
|
||||
return Err(exc);
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
use rustpython_vm::obj::objstr::PyStrRef;
|
||||
use rustpython_vm::builtins::PyStrRef;
|
||||
use rustpython_vm::pyobject::{BorrowValue, PyIterable, PyResult, TryFromObject};
|
||||
use rustpython_vm::scope::{NameProtocol, Scope};
|
||||
use rustpython_vm::VirtualMachine;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
use crate::builtins::int::PyIntRef;
|
||||
use crate::cformat::CFormatString;
|
||||
use crate::function::{single_or_tuple_any, OptionalOption};
|
||||
use crate::obj::objint::PyIntRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, PyIterator, PyObjectRef, PyResult, TryFromObject, TypeProtocol,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::objcode::PyCodeRef;
|
||||
use super::objtype::{self, PyTypeRef};
|
||||
use super::code::PyCodeRef;
|
||||
use super::pytype::{self, PyTypeRef};
|
||||
use crate::coroutine::{Coro, Variant};
|
||||
use crate::exceptions::PyBaseExceptionRef;
|
||||
use crate::frame::FrameRef;
|
||||
@@ -127,8 +127,8 @@ impl PyAsyncGenWrappedValue {}
|
||||
impl PyAsyncGenWrappedValue {
|
||||
fn unbox(ag: &PyAsyncGen, val: PyResult, vm: &VirtualMachine) -> PyResult {
|
||||
if let Err(ref e) = val {
|
||||
if objtype::isinstance(&e, &vm.ctx.exceptions.stop_async_iteration)
|
||||
|| objtype::isinstance(&e, &vm.ctx.exceptions.generator_exit)
|
||||
if pytype::isinstance(&e, &vm.ctx.exceptions.stop_async_iteration)
|
||||
|| pytype::isinstance(&e, &vm.ctx.exceptions.generator_exit)
|
||||
{
|
||||
ag.inner.closed.store(true);
|
||||
}
|
||||
@@ -385,8 +385,8 @@ impl PyAsyncGenAThrow {
|
||||
self.ag.running_async.store(false);
|
||||
self.state.store(AwaitableState::Closed);
|
||||
if self.aclose
|
||||
&& (objtype::isinstance(&exc, &vm.ctx.exceptions.stop_async_iteration)
|
||||
|| objtype::isinstance(&exc, &vm.ctx.exceptions.generator_exit))
|
||||
&& (pytype::isinstance(&exc, &vm.ctx.exceptions.stop_async_iteration)
|
||||
|| pytype::isinstance(&exc, &vm.ctx.exceptions.generator_exit))
|
||||
{
|
||||
vm.new_exception_empty(vm.ctx.exceptions.stop_iteration.clone())
|
||||
} else {
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::fmt;
|
||||
|
||||
use super::objclassmethod::PyClassMethod;
|
||||
use super::classmethod::PyClassMethod;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::common::borrow::BorrowValue;
|
||||
use crate::function::{FuncArgs, PyNativeFunc};
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
PyClassImpl, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
};
|
||||
@@ -1,4 +1,11 @@
|
||||
//! Implementation of the python bytearray object.
|
||||
use super::bytes::{PyBytes, PyBytesRef};
|
||||
use super::int::PyIntRef;
|
||||
use super::iter;
|
||||
use super::memory::{Buffer, BufferOptions};
|
||||
use super::pystr::PyStrRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use super::tuple::PyTupleRef;
|
||||
use crate::anystr::{self, AnyStr};
|
||||
use crate::bytesinner::{
|
||||
bytes_decode, ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions,
|
||||
@@ -10,13 +17,6 @@ use crate::common::lock::{
|
||||
PyRwLock, PyRwLockReadGuard, PyRwLockUpgradableReadGuard, PyRwLockWriteGuard,
|
||||
};
|
||||
use crate::function::{OptionalArg, OptionalOption};
|
||||
use crate::obj::objbytes::{PyBytes, PyBytesRef};
|
||||
use crate::obj::objint::PyIntRef;
|
||||
use crate::obj::objiter;
|
||||
use crate::obj::objmemory::{Buffer, BufferOptions};
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::objtuple::PyTupleRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, IdProtocol, IntoPyObject, PyClassImpl, PyComparisonValue, PyContext,
|
||||
PyIterable, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
@@ -656,7 +656,7 @@ impl PyByteArrayIterator {
|
||||
if let Some(&ret) = self.bytearray.borrow_value().elements.get(pos) {
|
||||
Ok(ret)
|
||||
} else {
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,17 +7,17 @@ use rustpython_common::{
|
||||
use std::mem::size_of;
|
||||
use std::ops::Deref;
|
||||
|
||||
use super::objint::PyIntRef;
|
||||
use super::objiter;
|
||||
use super::objstr::PyStrRef;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::int::PyIntRef;
|
||||
use super::iter;
|
||||
use super::pystr::PyStrRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::builtins::tuple::PyTupleRef;
|
||||
use crate::bytesinner::{
|
||||
bytes_decode, ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions,
|
||||
ByteInnerSplitOptions, ByteInnerTranslateOptions, DecodeArgs, PyBytesInner,
|
||||
};
|
||||
use crate::common::hash::PyHash;
|
||||
use crate::function::{OptionalArg, OptionalOption};
|
||||
use crate::obj::objtuple::PyTupleRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, IntoPyObject, PyClassImpl, PyComparisonValue, PyContext, PyIterable,
|
||||
PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
|
||||
@@ -29,7 +29,7 @@ use crate::{
|
||||
byteslike::PyBytesLike,
|
||||
};
|
||||
|
||||
use crate::obj::objmemory::{Buffer, BufferOptions};
|
||||
use crate::builtins::memory::{Buffer, BufferOptions};
|
||||
|
||||
/// "bytes(iterable_of_ints) -> bytes\n\
|
||||
/// bytes(string, encoding[, errors]) -> bytes\n\
|
||||
@@ -555,7 +555,7 @@ impl PyBytesIterator {
|
||||
if let Some(&ret) = self.bytes.borrow_value().get(pos) {
|
||||
Ok(ret)
|
||||
} else {
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
};
|
||||
@@ -5,7 +5,7 @@
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::bytecode;
|
||||
use crate::pyobject::{IdProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
@@ -1,9 +1,9 @@
|
||||
use num_complex::Complex64;
|
||||
use num_traits::Zero;
|
||||
|
||||
use super::objfloat;
|
||||
use super::objstr::PyStr;
|
||||
use super::objtype::{self, PyTypeRef};
|
||||
use super::float;
|
||||
use super::pystr::PyStr;
|
||||
use super::pytype::{self, PyTypeRef};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IntoPyObject, Never, PyArithmaticValue, PyClassImpl, PyComparisonValue, PyContext,
|
||||
PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
@@ -48,7 +48,7 @@ pub fn init(context: &PyContext) {
|
||||
fn try_complex(value: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<Complex64>> {
|
||||
let r = if let Some(complex) = value.payload_if_subclass::<PyComplex>(vm) {
|
||||
Some(complex.value)
|
||||
} else if let Some(float) = objfloat::try_float(value, vm)? {
|
||||
} else if let Some(float) = float::try_float(value, vm)? {
|
||||
Some(Complex64::new(float, 0.0))
|
||||
} else {
|
||||
None
|
||||
@@ -253,7 +253,7 @@ impl PyComplex {
|
||||
Some(obj) => {
|
||||
if let Some(c) = try_complex(&obj, vm)? {
|
||||
c
|
||||
} else if objtype::issubclass(obj.class(), &vm.ctx.types.str_type) {
|
||||
} else if pytype::issubclass(obj.class(), &vm.ctx.types.str_type) {
|
||||
return Err(
|
||||
vm.new_type_error("complex() second arg can't be a string".to_owned())
|
||||
);
|
||||
@@ -289,7 +289,7 @@ impl Comparable for PyComplex {
|
||||
let result = if let Some(other) = other.payload_if_subclass::<PyComplex>(vm) {
|
||||
zelf.value == other.value
|
||||
} else {
|
||||
match objfloat::try_float(&other, vm) {
|
||||
match float::try_float(&other, vm) {
|
||||
Ok(Some(other)) => zelf.value == other.into(),
|
||||
Err(_) => false,
|
||||
Ok(None) => return Ok(PyComparisonValue::NotImplemented),
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::objcode::PyCodeRef;
|
||||
use super::objstr::PyStrRef;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::code::PyCodeRef;
|
||||
use super::pystr::PyStrRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::coroutine::{Coro, Variant};
|
||||
use crate::frame::FrameRef;
|
||||
use crate::function::OptionalArg;
|
||||
@@ -2,10 +2,10 @@ use crossbeam_utils::atomic::AtomicCell;
|
||||
use std::fmt;
|
||||
use std::mem::size_of;
|
||||
|
||||
use super::objiter;
|
||||
use super::objset::PySet;
|
||||
use super::objstr;
|
||||
use super::objtype::{self, PyTypeRef};
|
||||
use super::iter;
|
||||
use super::pystr;
|
||||
use super::pytype::{self, PyTypeRef};
|
||||
use super::set::PySet;
|
||||
use crate::dictdatatype::{self, DictKey};
|
||||
use crate::exceptions::PyBaseExceptionRef;
|
||||
use crate::function::{FuncArgs, KwArgs, OptionalArg};
|
||||
@@ -83,25 +83,25 @@ impl PyDict {
|
||||
dict.insert(vm, key, value)?;
|
||||
}
|
||||
} else if let Some(keys) = vm.get_method(dict_obj.clone(), "keys") {
|
||||
let keys = objiter::get_iter(vm, &vm.invoke(&keys?, ())?)?;
|
||||
while let Some(key) = objiter::get_next_object(vm, &keys)? {
|
||||
let keys = iter::get_iter(vm, &vm.invoke(&keys?, ())?)?;
|
||||
while let Some(key) = iter::get_next_object(vm, &keys)? {
|
||||
let val = dict_obj.get_item(key.clone(), vm)?;
|
||||
dict.insert(vm, key, val)?;
|
||||
}
|
||||
} else {
|
||||
let iter = objiter::get_iter(vm, &dict_obj)?;
|
||||
let iter = iter::get_iter(vm, &dict_obj)?;
|
||||
loop {
|
||||
fn err(vm: &VirtualMachine) -> PyBaseExceptionRef {
|
||||
vm.new_value_error("Iterator must have exactly two elements".to_owned())
|
||||
}
|
||||
let element = match objiter::get_next_object(vm, &iter)? {
|
||||
let element = match iter::get_next_object(vm, &iter)? {
|
||||
Some(obj) => obj,
|
||||
None => break,
|
||||
};
|
||||
let elem_iter = objiter::get_iter(vm, &element)?;
|
||||
let key = objiter::get_next_object(vm, &elem_iter)?.ok_or_else(|| err(vm))?;
|
||||
let value = objiter::get_next_object(vm, &elem_iter)?.ok_or_else(|| err(vm))?;
|
||||
if objiter::get_next_object(vm, &elem_iter)?.is_some() {
|
||||
let elem_iter = iter::get_iter(vm, &element)?;
|
||||
let key = iter::get_next_object(vm, &elem_iter)?.ok_or_else(|| err(vm))?;
|
||||
let value = iter::get_next_object(vm, &elem_iter)?.ok_or_else(|| err(vm))?;
|
||||
if iter::get_next_object(vm, &elem_iter)?.is_some() {
|
||||
return Err(err(vm));
|
||||
}
|
||||
dict.insert(vm, key, value)?;
|
||||
@@ -443,7 +443,7 @@ impl PyDictRef {
|
||||
pub fn to_attributes(self) -> PyAttributes {
|
||||
let mut attrs = PyAttributes::new();
|
||||
for (key, value) in self {
|
||||
let key = objstr::clone_value(&key);
|
||||
let key = pystr::clone_value(&key);
|
||||
attrs.insert(key, value);
|
||||
}
|
||||
attrs
|
||||
@@ -468,7 +468,7 @@ impl PyDictRef {
|
||||
// We can take the short path here!
|
||||
match self.inner_getitem_option(key, vm) {
|
||||
Err(exc) => {
|
||||
if objtype::isinstance(&exc, &vm.ctx.exceptions.key_error) {
|
||||
if pytype::isinstance(&exc, &vm.ctx.exceptions.key_error) {
|
||||
Ok(None)
|
||||
} else {
|
||||
Err(exc)
|
||||
@@ -482,7 +482,7 @@ impl PyDictRef {
|
||||
match self.get_item(key, vm) {
|
||||
Ok(value) => Ok(Some(value)),
|
||||
Err(exc) => {
|
||||
if objtype::isinstance(&exc, &vm.ctx.exceptions.key_error) {
|
||||
if pytype::isinstance(&exc, &vm.ctx.exceptions.key_error) {
|
||||
Ok(None)
|
||||
} else {
|
||||
Err(exc)
|
||||
@@ -681,7 +681,7 @@ macro_rules! dict_iterator {
|
||||
self.position.store(position);
|
||||
Ok($result_fn(vm, key, value))
|
||||
}
|
||||
None => Err(objiter::new_stop_iteration(vm)),
|
||||
None => Err(iter::new_stop_iteration(vm)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,7 +736,7 @@ macro_rules! dict_iterator {
|
||||
}
|
||||
None => {
|
||||
self.position.store(std::isize::MAX as usize);
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,9 @@ use std::ops::AddAssign;
|
||||
use num_bigint::BigInt;
|
||||
use num_traits::Zero;
|
||||
|
||||
use super::objint::PyIntRef;
|
||||
use super::objiter;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::int::PyIntRef;
|
||||
use super::iter;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::pyobject::{BorrowValue, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
@@ -39,7 +39,7 @@ impl PyEnumerate {
|
||||
OptionalArg::Missing => BigInt::zero(),
|
||||
};
|
||||
|
||||
let iterator = objiter::get_iter(vm, &iterable)?;
|
||||
let iterator = iter::get_iter(vm, &iterable)?;
|
||||
PyEnumerate {
|
||||
counter: PyRwLock::new(counter),
|
||||
iterator,
|
||||
@@ -49,7 +49,7 @@ impl PyEnumerate {
|
||||
|
||||
#[pymethod(name = "__next__")]
|
||||
fn next(&self, vm: &VirtualMachine) -> PyResult<(BigInt, PyObjectRef)> {
|
||||
let next_obj = objiter::call_next(vm, &self.iterator)?;
|
||||
let next_obj = iter::call_next(vm, &self.iterator)?;
|
||||
let mut counter = self.counter.write();
|
||||
let position = counter.clone();
|
||||
AddAssign::add_assign(&mut counter as &mut BigInt, 1);
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::objbool;
|
||||
use super::objiter;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::iter;
|
||||
use super::pybool;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::pyobject::{PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
@@ -32,7 +32,7 @@ impl PyFilter {
|
||||
iterable: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyFilterRef> {
|
||||
let iterator = objiter::get_iter(vm, &iterable)?;
|
||||
let iterator = iter::get_iter(vm, &iterable)?;
|
||||
|
||||
PyFilter {
|
||||
predicate: function,
|
||||
@@ -46,7 +46,7 @@ impl PyFilter {
|
||||
let predicate = &self.predicate;
|
||||
let iterator = &self.iterator;
|
||||
loop {
|
||||
let next_obj = objiter::call_next(vm, iterator)?;
|
||||
let next_obj = iter::call_next(vm, iterator)?;
|
||||
let predicate_value = if vm.is_none(predicate) {
|
||||
next_obj.clone()
|
||||
} else {
|
||||
@@ -54,7 +54,7 @@ impl PyFilter {
|
||||
// iteration
|
||||
vm.invoke(&predicate, vec![next_obj.clone()])?
|
||||
};
|
||||
if objbool::boolval(vm, predicate_value)? {
|
||||
if pybool::boolval(vm, predicate_value)? {
|
||||
return Ok(next_obj);
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@ use num_complex::Complex64;
|
||||
use num_rational::Ratio;
|
||||
use num_traits::{pow, ToPrimitive, Zero};
|
||||
|
||||
use super::objbytes::PyBytes;
|
||||
use super::objint::{self, PyInt, PyIntRef};
|
||||
use super::objstr::{PyStr, PyStrRef};
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::bytes::PyBytes;
|
||||
use super::int::{self, PyInt, PyIntRef};
|
||||
use super::pystr::{PyStr, PyStrRef};
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::format::FormatSpec;
|
||||
use crate::function::{OptionalArg, OptionalOption};
|
||||
use crate::pyobject::{
|
||||
@@ -59,7 +59,7 @@ pub fn try_float(obj: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<f64>
|
||||
let v = if let Some(float) = obj.payload_if_subclass::<PyFloat>(vm) {
|
||||
Some(float.value)
|
||||
} else if let Some(int) = obj.payload_if_subclass::<PyInt>(vm) {
|
||||
Some(objint::try_float(int.borrow_value(), vm)?)
|
||||
Some(int::try_float(int.borrow_value(), vm)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -495,7 +495,7 @@ fn to_float(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<f64> {
|
||||
let value = if let Some(float) = obj.payload_if_subclass::<PyFloat>(vm) {
|
||||
float.value
|
||||
} else if let Some(int) = obj.payload_if_subclass::<PyInt>(vm) {
|
||||
objint::try_float(int.borrow_value(), vm)?
|
||||
int::try_float(int.borrow_value(), vm)?
|
||||
} else if let Some(s) = obj.payload_if_subclass::<PyStr>(vm) {
|
||||
float_ops::parse_str(s.borrow_value().trim()).ok_or_else(|| {
|
||||
vm.new_value_error(format!("could not convert string to float: '{}'", s))
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
*/
|
||||
|
||||
use super::objcode::PyCodeRef;
|
||||
use super::objdict::PyDictRef;
|
||||
use super::objstr::PyStrRef;
|
||||
use super::code::PyCodeRef;
|
||||
use super::dict::PyDictRef;
|
||||
use super::pystr::PyStrRef;
|
||||
use crate::frame::FrameRef;
|
||||
use crate::pyobject::{IdProtocol, PyClassImpl, PyContext, PyObjectRef, PyResult};
|
||||
use crate::vm::VirtualMachine;
|
||||
@@ -1,17 +1,17 @@
|
||||
#[cfg(feature = "jit")]
|
||||
mod jitfunc;
|
||||
|
||||
use super::objcode::PyCodeRef;
|
||||
use super::objdict::PyDictRef;
|
||||
use super::objstr::PyStrRef;
|
||||
use super::objtuple::PyTupleRef;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::code::PyCodeRef;
|
||||
use super::dict::PyDictRef;
|
||||
use super::pystr::PyStrRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use super::tuple::PyTupleRef;
|
||||
use crate::builtins::asyncgenerator::PyAsyncGen;
|
||||
use crate::builtins::coroutine::PyCoroutine;
|
||||
use crate::builtins::generator::PyGenerator;
|
||||
use crate::bytecode;
|
||||
use crate::frame::Frame;
|
||||
use crate::function::FuncArgs;
|
||||
use crate::obj::objasyncgenerator::PyAsyncGen;
|
||||
use crate::obj::objcoroutine::PyCoroutine;
|
||||
use crate::obj::objgenerator::PyGenerator;
|
||||
#[cfg(feature = "jit")]
|
||||
use crate::pyobject::IntoPyObject;
|
||||
use crate::pyobject::{
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::builtins::dict::PyDictRef;
|
||||
use crate::builtins::function::{PyFunction, PyFunctionRef};
|
||||
use crate::builtins::{float, int};
|
||||
use crate::exceptions::PyBaseExceptionRef;
|
||||
use crate::function::FuncArgs;
|
||||
use crate::obj::objdict::PyDictRef;
|
||||
use crate::obj::objfunction::{PyFunction, PyFunctionRef};
|
||||
use crate::obj::{objfloat, objint};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IdProtocol, IntoPyObject, ItemProtocol, PyObjectRef, PyResult, TryFromObject,
|
||||
TypeProtocol,
|
||||
@@ -107,12 +107,12 @@ fn get_jit_value(vm: &VirtualMachine, obj: &PyObjectRef) -> Result<AbiValue, Arg
|
||||
// This does exact type checks as subclasses of int/float can't be passed to jitted functions
|
||||
let cls = obj.class();
|
||||
if cls.is(&vm.ctx.types.int_type) {
|
||||
objint::get_value(&obj)
|
||||
int::get_value(&obj)
|
||||
.to_i64()
|
||||
.map(AbiValue::Int)
|
||||
.ok_or(ArgsError::IntOverflow)
|
||||
} else if cls.is(&vm.ctx.types.float_type) {
|
||||
Ok(AbiValue::Float(objfloat::get_value(&obj)))
|
||||
Ok(AbiValue::Float(float::get_value(&obj)))
|
||||
} else {
|
||||
Err(ArgsError::NonJitType)
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
* The mythical generator.
|
||||
*/
|
||||
|
||||
use super::objcode::PyCodeRef;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::code::PyCodeRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::coroutine::{Coro, Variant};
|
||||
use crate::frame::FrameRef;
|
||||
use crate::function::OptionalArg;
|
||||
@@ -1,7 +1,7 @@
|
||||
/*! Python `attribute` descriptor class. (PyGetSet)
|
||||
|
||||
*/
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::function::{OwnedParam, RefParam};
|
||||
use crate::pyobject::{
|
||||
IntoPyResult, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
|
||||
@@ -7,12 +7,12 @@ use num_bigint::{BigInt, BigUint, Sign};
|
||||
use num_integer::Integer;
|
||||
use num_traits::{One, Pow, PrimInt, Signed, ToPrimitive, Zero};
|
||||
|
||||
use super::objbool::IntoPyBool;
|
||||
use super::objbytearray::PyByteArray;
|
||||
use super::objbytes::PyBytes;
|
||||
use super::objfloat;
|
||||
use super::objstr::{PyStr, PyStrRef};
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::bytearray::PyByteArray;
|
||||
use super::bytes::PyBytes;
|
||||
use super::float;
|
||||
use super::pybool::IntoPyBool;
|
||||
use super::pystr::{PyStr, PyStrRef};
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::format::FormatSpec;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::pyobject::{
|
||||
@@ -132,7 +132,7 @@ fn inner_pow(int1: &BigInt, int2: &BigInt, vm: &VirtualMachine) -> PyResult {
|
||||
if int2.is_negative() {
|
||||
let v1 = try_float(int1, vm)?;
|
||||
let v2 = try_float(int2, vm)?;
|
||||
objfloat::float_pow(v1, v2, vm).into_pyresult(vm)
|
||||
float::float_pow(v1, v2, vm).into_pyresult(vm)
|
||||
} else {
|
||||
Ok(if let Some(v2) = int2.to_u64() {
|
||||
vm.ctx.new_int(Pow::pow(int1, v2))
|
||||
@@ -5,8 +5,8 @@
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use num_traits::Signed;
|
||||
|
||||
use super::objint::{self, PyInt};
|
||||
use super::objtype::{self, PyTypeRef};
|
||||
use super::int::{self, PyInt};
|
||||
use super::pytype::{self, PyTypeRef};
|
||||
use crate::exceptions::PyBaseExceptionRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, PyCallable, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
@@ -58,7 +58,7 @@ pub fn get_next_object(
|
||||
Ok(value) => Ok(Some(value)),
|
||||
Err(next_error) => {
|
||||
// Check if we have stopiteration, or something else:
|
||||
if objtype::isinstance(&next_error, &vm.ctx.exceptions.stop_iteration) {
|
||||
if pytype::isinstance(&next_error, &vm.ctx.exceptions.stop_iteration) {
|
||||
Ok(None)
|
||||
} else {
|
||||
Err(next_error)
|
||||
@@ -103,7 +103,7 @@ pub fn length_hint(vm: &VirtualMachine, iter: PyObjectRef) -> PyResult<Option<us
|
||||
match len {
|
||||
Ok(len) => return Ok(Some(len)),
|
||||
Err(e) => {
|
||||
if !objtype::isinstance(&e, &vm.ctx.exceptions.type_error) {
|
||||
if !pytype::isinstance(&e, &vm.ctx.exceptions.type_error) {
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ pub fn length_hint(vm: &VirtualMachine, iter: PyObjectRef) -> PyResult<Option<us
|
||||
let result = match vm.invoke(&hint, ()) {
|
||||
Ok(res) => res,
|
||||
Err(e) => {
|
||||
return if objtype::isinstance(&e, &vm.ctx.exceptions.type_error) {
|
||||
return if pytype::isinstance(&e, &vm.ctx.exceptions.type_error) {
|
||||
Ok(None)
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -135,7 +135,7 @@ pub fn length_hint(vm: &VirtualMachine, iter: PyObjectRef) -> PyResult<Option<us
|
||||
if result.is_negative() {
|
||||
return Err(vm.new_value_error("__length_hint__() should return >= 0".to_owned()));
|
||||
}
|
||||
let hint = objint::try_to_primitive(result, vm)?;
|
||||
let hint = int::try_to_primitive(result, vm)?;
|
||||
Ok(Some(hint))
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ impl PySequenceIterator {
|
||||
let pos = self.position.fetch_add(step);
|
||||
if pos >= 0 {
|
||||
match vm.call_method(&self.obj, "__getitem__", (pos,)) {
|
||||
Err(ref e) if objtype::isinstance(&e, &vm.ctx.exceptions.index_error) => {
|
||||
Err(ref e) if pytype::isinstance(&e, &vm.ctx.exceptions.index_error) => {
|
||||
Err(new_stop_iteration(vm))
|
||||
}
|
||||
// also catches stop_iteration => stop_iteration
|
||||
@@ -6,10 +6,10 @@ use std::ops::DerefMut;
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use num_traits::ToPrimitive;
|
||||
|
||||
use super::objint::PyIntRef;
|
||||
use super::objiter;
|
||||
use super::objslice::PySliceRef;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::int::PyIntRef;
|
||||
use super::iter;
|
||||
use super::pytype::PyTypeRef;
|
||||
use super::slice::PySliceRef;
|
||||
use crate::bytesinner;
|
||||
use crate::common::lock::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard};
|
||||
use crate::function::OptionalArg;
|
||||
@@ -474,7 +474,7 @@ impl PyListIterator {
|
||||
if let Some(obj) = list.get(pos) {
|
||||
Ok(obj.clone())
|
||||
} else {
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,7 +515,7 @@ impl PyListReverseIterator {
|
||||
return Ok(ret.clone());
|
||||
}
|
||||
}
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
}
|
||||
|
||||
#[pymethod(name = "__iter__")]
|
||||
@@ -17,19 +17,19 @@ mod decl {
|
||||
use rustpython_parser::parser;
|
||||
|
||||
use super::to_ascii;
|
||||
use crate::builtins::bytes::PyBytesRef;
|
||||
use crate::builtins::code::PyCodeRef;
|
||||
use crate::builtins::dict::PyDictRef;
|
||||
use crate::builtins::function::PyFunctionRef;
|
||||
use crate::builtins::int::{self, PyIntRef};
|
||||
use crate::builtins::iter;
|
||||
use crate::builtins::list::{PyList, SortOptions};
|
||||
use crate::builtins::pybool::{self, IntoPyBool};
|
||||
use crate::builtins::pystr::{PyStr, PyStrRef};
|
||||
use crate::builtins::pytype::{self, PyTypeRef};
|
||||
use crate::byteslike::PyBytesLike;
|
||||
use crate::exceptions::PyBaseExceptionRef;
|
||||
use crate::function::{single_or_tuple_any, Args, FuncArgs, KwArgs, OptionalArg};
|
||||
use crate::obj::objbool::{self, IntoPyBool};
|
||||
use crate::obj::objbytes::PyBytesRef;
|
||||
use crate::obj::objcode::PyCodeRef;
|
||||
use crate::obj::objdict::PyDictRef;
|
||||
use crate::obj::objfunction::PyFunctionRef;
|
||||
use crate::obj::objint::{self, PyIntRef};
|
||||
use crate::obj::objiter;
|
||||
use crate::obj::objlist::{PyList, SortOptions};
|
||||
use crate::obj::objstr::{PyStr, PyStrRef};
|
||||
use crate::obj::objtype::{self, PyTypeRef};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, IdProtocol, ItemProtocol, PyCallable, PyIterable, PyObjectRef,
|
||||
PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
@@ -292,7 +292,7 @@ mod decl {
|
||||
default: T,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<T> {
|
||||
if objtype::isinstance(&ex, &vm.ctx.exceptions.attribute_error) {
|
||||
if pytype::isinstance(&ex, &vm.ctx.exceptions.attribute_error) {
|
||||
Ok(default)
|
||||
} else {
|
||||
Err(ex)
|
||||
@@ -432,11 +432,11 @@ mod decl {
|
||||
) -> PyResult {
|
||||
if let OptionalArg::Present(sentinel) = sentinel {
|
||||
let callable = PyCallable::try_from_object(vm, iter_target)?;
|
||||
Ok(objiter::PyCallableIterator::new(callable, sentinel)
|
||||
Ok(iter::PyCallableIterator::new(callable, sentinel)
|
||||
.into_ref(vm)
|
||||
.into_object())
|
||||
} else {
|
||||
objiter::get_iter(vm, &iter_target)
|
||||
iter::get_iter(vm, &iter_target)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,7 +568,7 @@ mod decl {
|
||||
match vm.call_method(&iterator, "__next__", ()) {
|
||||
Ok(value) => Ok(value),
|
||||
Err(value) => {
|
||||
if objtype::isinstance(&value, &vm.ctx.exceptions.stop_iteration) {
|
||||
if pytype::isinstance(&value, &vm.ctx.exceptions.stop_iteration) {
|
||||
match default_value {
|
||||
OptionalArg::Missing => Err(value),
|
||||
OptionalArg::Present(value) => Ok(value),
|
||||
@@ -639,15 +639,15 @@ mod decl {
|
||||
}
|
||||
OptionalArg::Present(m) => {
|
||||
// Check if the 3rd argument is defined and perform modulus on the result
|
||||
if !(objtype::isinstance(&x, &vm.ctx.types.int_type)
|
||||
&& objtype::isinstance(&y, &vm.ctx.types.int_type))
|
||||
if !(pytype::isinstance(&x, &vm.ctx.types.int_type)
|
||||
&& pytype::isinstance(&y, &vm.ctx.types.int_type))
|
||||
{
|
||||
return Err(vm.new_type_error(
|
||||
"pow() 3rd argument not allowed unless all arguments are integers"
|
||||
.to_owned(),
|
||||
));
|
||||
}
|
||||
let y = objint::get_value(&y);
|
||||
let y = int::get_value(&y);
|
||||
if y.sign() == Sign::Minus {
|
||||
return Err(vm.new_value_error(
|
||||
"pow() 2nd argument cannot be negative when 3rd argument specified"
|
||||
@@ -658,7 +658,7 @@ mod decl {
|
||||
if m.is_zero() {
|
||||
return Err(vm.new_value_error("pow() 3rd argument cannot be 0".to_owned()));
|
||||
}
|
||||
let x = objint::get_value(&x);
|
||||
let x = int::get_value(&x);
|
||||
Ok(vm.ctx.new_int(x.modpow(&y, &m)))
|
||||
}
|
||||
}
|
||||
@@ -729,8 +729,8 @@ mod decl {
|
||||
"argument to reversed() must be a sequence".to_owned()
|
||||
})?;
|
||||
let len = vm.call_method(&obj, "__len__", ())?;
|
||||
let len = objint::get_value(&len).to_isize().unwrap();
|
||||
let obj_iterator = objiter::PySequenceIterator::new_reversed(obj, len);
|
||||
let len = int::get_value(&len).to_isize().unwrap();
|
||||
let obj_iterator = iter::PySequenceIterator::new_reversed(obj, len);
|
||||
Ok(obj_iterator.into_object(vm))
|
||||
}
|
||||
}
|
||||
@@ -825,9 +825,9 @@ mod decl {
|
||||
|
||||
for base in bases.clone() {
|
||||
let base_class = base.class();
|
||||
if objtype::issubclass(&base_class, &metaclass) {
|
||||
if pytype::issubclass(&base_class, &metaclass) {
|
||||
metaclass = base.clone_class();
|
||||
} else if !objtype::issubclass(&metaclass, &base_class) {
|
||||
} else if !pytype::issubclass(&metaclass, &base_class) {
|
||||
return Err(vm.new_type_error(
|
||||
"metaclass conflict: the metaclass of a derived class must be a (non-strict) \
|
||||
subclass of the metaclasses of all its bases"
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::objiter;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::iter;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::function::Args;
|
||||
use crate::pyobject::{PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
@@ -33,7 +33,7 @@ impl PyMap {
|
||||
) -> PyResult<PyMapRef> {
|
||||
let iterators = iterables
|
||||
.into_iter()
|
||||
.map(|iterable| objiter::get_iter(vm, &iterable))
|
||||
.map(|iterable| iter::get_iter(vm, &iterable))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
PyMap {
|
||||
mapper: function,
|
||||
@@ -47,7 +47,7 @@ impl PyMap {
|
||||
let next_objs = self
|
||||
.iterators
|
||||
.iter()
|
||||
.map(|iterator| objiter::call_next(vm, iterator))
|
||||
.map(|iterator| iter::call_next(vm, iterator))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
// the mapper itself can raise StopIteration which does stop the map iteration
|
||||
@@ -62,7 +62,7 @@ impl PyMap {
|
||||
#[pymethod(name = "__length_hint__")]
|
||||
fn length_hint(&self, vm: &VirtualMachine) -> PyResult<usize> {
|
||||
self.iterators.iter().try_fold(0, |prev, cur| {
|
||||
let cur = objiter::length_hint(vm, cur.clone())?.unwrap_or(0);
|
||||
let cur = iter::length_hint(vm, cur.clone())?.unwrap_or(0);
|
||||
let max = std::cmp::max(prev, cur);
|
||||
Ok(max)
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::objdict::PyDict;
|
||||
use super::objiter;
|
||||
use super::objstr::PyStrRef;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::dict::PyDict;
|
||||
use super::iter;
|
||||
use super::pystr::PyStrRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IntoPyObject, ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult,
|
||||
@@ -94,7 +94,7 @@ impl PyMappingProxy {
|
||||
PyDict::from_attributes(c.attributes.read().clone(), vm)?.into_pyobject(vm)
|
||||
}
|
||||
};
|
||||
objiter::get_iter(vm, &obj)
|
||||
iter::get_iter(vm, &obj)
|
||||
}
|
||||
#[pymethod]
|
||||
pub fn items(&self, vm: &VirtualMachine) -> PyResult {
|
||||
@@ -1,14 +1,14 @@
|
||||
use std::{fmt::Debug, ops::Deref};
|
||||
|
||||
use crate::builtins::bytes::{PyBytes, PyBytesRef};
|
||||
use crate::builtins::list::{PyList, PyListRef};
|
||||
use crate::builtins::pystr::{PyStr, PyStrRef};
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::builtins::slice::PySliceRef;
|
||||
use crate::bytesinner::bytes_to_hex;
|
||||
use crate::common::borrow::{BorrowedValue, BorrowedValueMut};
|
||||
use crate::common::hash::PyHash;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::obj::objbytes::{PyBytes, PyBytesRef};
|
||||
use crate::obj::objlist::{PyList, PyListRef};
|
||||
use crate::obj::objslice::PySliceRef;
|
||||
use crate::obj::objstr::{PyStr, PyStrRef};
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
Either, IdProtocol, IntoPyObject, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef,
|
||||
PyRef, PyResult, PyThreadingConstraint, PyValue, TypeProtocol,
|
||||
@@ -0,0 +1,85 @@
|
||||
//! This package contains the python basic/builtin types
|
||||
|
||||
pub(crate) mod asyncgenerator;
|
||||
pub use asyncgenerator::*;
|
||||
pub(crate) mod builtinfunc;
|
||||
pub use builtinfunc::*;
|
||||
pub(crate) mod bytearray;
|
||||
pub use bytearray::*;
|
||||
pub(crate) mod bytes;
|
||||
pub use bytes::*;
|
||||
pub(crate) mod classmethod;
|
||||
pub use classmethod::*;
|
||||
pub(crate) mod code;
|
||||
pub use code::*;
|
||||
pub(crate) mod complex;
|
||||
pub use complex::*;
|
||||
pub(crate) mod coroutine;
|
||||
pub use coroutine::*;
|
||||
pub(crate) mod dict;
|
||||
pub use dict::*;
|
||||
pub(crate) mod enumerate;
|
||||
pub use enumerate::*;
|
||||
pub(crate) mod filter;
|
||||
pub use filter::*;
|
||||
pub(crate) mod float;
|
||||
pub use float::*;
|
||||
pub(crate) mod frame;
|
||||
pub use frame::*;
|
||||
pub(crate) mod function;
|
||||
pub use function::*;
|
||||
pub(crate) mod generator;
|
||||
pub use generator::*;
|
||||
pub(crate) mod getset;
|
||||
pub use getset::*;
|
||||
pub(crate) mod int;
|
||||
pub use int::*;
|
||||
pub(crate) mod iter;
|
||||
pub use iter::*;
|
||||
pub(crate) mod list;
|
||||
pub use list::*;
|
||||
pub(crate) mod map;
|
||||
pub use map::*;
|
||||
pub(crate) mod mappingproxy;
|
||||
pub use mappingproxy::*;
|
||||
pub(crate) mod memory;
|
||||
pub use memory::*;
|
||||
pub(crate) mod module;
|
||||
pub use module::*;
|
||||
pub(crate) mod namespace;
|
||||
pub use namespace::*;
|
||||
pub(crate) mod object;
|
||||
pub use object::*;
|
||||
pub(crate) mod property;
|
||||
pub use property::*;
|
||||
pub(crate) mod pybool;
|
||||
pub use pybool::*;
|
||||
pub(crate) mod pystr;
|
||||
pub use pystr::*;
|
||||
pub(crate) mod pysuper;
|
||||
pub use pysuper::*;
|
||||
pub(crate) mod pytype;
|
||||
pub use pytype::*;
|
||||
pub(crate) mod range;
|
||||
pub use range::*;
|
||||
pub(crate) mod set;
|
||||
pub use set::*;
|
||||
pub(crate) mod singletons;
|
||||
pub use singletons::*;
|
||||
pub(crate) mod slice;
|
||||
pub use slice::*;
|
||||
pub(crate) mod staticmethod;
|
||||
pub use staticmethod::*;
|
||||
pub(crate) mod traceback;
|
||||
pub use traceback::*;
|
||||
pub(crate) mod tuple;
|
||||
pub use tuple::*;
|
||||
pub(crate) mod weakproxy;
|
||||
pub use weakproxy::*;
|
||||
pub(crate) mod weakref;
|
||||
pub use weakref::*;
|
||||
pub(crate) mod zip;
|
||||
pub use zip::*;
|
||||
|
||||
mod make_module;
|
||||
pub use make_module::*;
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::objdict::PyDictRef;
|
||||
use super::objstr::{PyStr, PyStrRef};
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::dict::PyDictRef;
|
||||
use super::pystr::{PyStr, PyStrRef};
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::function::{FuncArgs, OptionalOption};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IntoPyObject, ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult,
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::function::KwArgs;
|
||||
use crate::pyobject::{PyClassImpl, PyContext, PyRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
@@ -1,11 +1,11 @@
|
||||
use super::objbool;
|
||||
use super::objdict::{PyDict, PyDictRef};
|
||||
use super::objlist::PyList;
|
||||
use super::objstr::PyStrRef;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::dict::{PyDict, PyDictRef};
|
||||
use super::list::PyList;
|
||||
use super::pybool;
|
||||
use super::pystr::PyStrRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::builtins::pytype::PyType;
|
||||
use crate::common::hash::PyHash;
|
||||
use crate::function::{FuncArgs, OptionalArg};
|
||||
use crate::obj::objtype::PyType;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, IdProtocol, ItemProtocol, PyArithmaticValue, PyAttributes, PyClassImpl,
|
||||
PyComparisonValue, PyContext, PyObject, PyObjectRef, PyResult, PyValue, TryFromObject,
|
||||
@@ -71,7 +71,7 @@ impl PyBaseObject {
|
||||
.unwrap();
|
||||
let value = match cmp(zelf, other, PyComparisonOp::Eq, vm)? {
|
||||
Either::A(obj) => PyArithmaticValue::from_object(vm, obj)
|
||||
.map(|obj| objbool::boolval(vm, obj))
|
||||
.map(|obj| pybool::boolval(vm, obj))
|
||||
.transpose()?,
|
||||
Either::B(value) => value,
|
||||
};
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
use crate::common::lock::PyRwLock;
|
||||
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::function::FuncArgs;
|
||||
use crate::pyobject::{
|
||||
PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
@@ -8,9 +8,9 @@ use crate::pyobject::{
|
||||
};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
use super::objint::PyInt;
|
||||
use super::objstr::PyStrRef;
|
||||
use super::objtype;
|
||||
use super::int::PyInt;
|
||||
use super::pystr::PyStrRef;
|
||||
use super::pytype;
|
||||
|
||||
impl IntoPyObject for bool {
|
||||
fn into_pyobject(self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
@@ -20,7 +20,7 @@ impl IntoPyObject for bool {
|
||||
|
||||
impl TryFromObject for bool {
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<bool> {
|
||||
if objtype::isinstance(&obj, &vm.ctx.types.int_type) {
|
||||
if pytype::isinstance(&obj, &vm.ctx.types.int_type) {
|
||||
Ok(get_value(&obj))
|
||||
} else {
|
||||
Err(vm.new_type_error(format!("Expected type bool, not {}", obj.class().name)))
|
||||
@@ -41,7 +41,7 @@ pub fn boolval(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<bool> {
|
||||
// If descriptor returns Error, propagate it further
|
||||
let method = method_or_err?;
|
||||
let bool_obj = vm.invoke(&method, ())?;
|
||||
if !objtype::isinstance(&bool_obj, &vm.ctx.types.bool_type) {
|
||||
if !pytype::isinstance(&bool_obj, &vm.ctx.types.bool_type) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"__bool__ should return bool, returned type {}",
|
||||
bool_obj.class().name
|
||||
@@ -100,8 +100,8 @@ impl PyBool {
|
||||
#[pymethod(name = "__ror__")]
|
||||
#[pymethod(magic)]
|
||||
fn or(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
if objtype::isinstance(&lhs, &vm.ctx.types.bool_type)
|
||||
&& objtype::isinstance(&rhs, &vm.ctx.types.bool_type)
|
||||
if pytype::isinstance(&lhs, &vm.ctx.types.bool_type)
|
||||
&& pytype::isinstance(&rhs, &vm.ctx.types.bool_type)
|
||||
{
|
||||
let lhs = get_value(&lhs);
|
||||
let rhs = get_value(&rhs);
|
||||
@@ -114,8 +114,8 @@ impl PyBool {
|
||||
#[pymethod(name = "__rand__")]
|
||||
#[pymethod(magic)]
|
||||
fn and(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
if objtype::isinstance(&lhs, &vm.ctx.types.bool_type)
|
||||
&& objtype::isinstance(&rhs, &vm.ctx.types.bool_type)
|
||||
if pytype::isinstance(&lhs, &vm.ctx.types.bool_type)
|
||||
&& pytype::isinstance(&rhs, &vm.ctx.types.bool_type)
|
||||
{
|
||||
let lhs = get_value(&lhs);
|
||||
let rhs = get_value(&rhs);
|
||||
@@ -128,8 +128,8 @@ impl PyBool {
|
||||
#[pymethod(name = "__rxor__")]
|
||||
#[pymethod(magic)]
|
||||
fn xor(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
|
||||
if objtype::isinstance(&lhs, &vm.ctx.types.bool_type)
|
||||
&& objtype::isinstance(&rhs, &vm.ctx.types.bool_type)
|
||||
if pytype::isinstance(&lhs, &vm.ctx.types.bool_type)
|
||||
&& pytype::isinstance(&rhs, &vm.ctx.types.bool_type)
|
||||
{
|
||||
let lhs = get_value(&lhs);
|
||||
let rhs = get_value(&rhs);
|
||||
@@ -141,7 +141,7 @@ impl PyBool {
|
||||
|
||||
#[pyslot]
|
||||
fn tp_new(zelf: PyObjectRef, x: OptionalArg<PyObjectRef>, vm: &VirtualMachine) -> PyResult {
|
||||
if !objtype::isinstance(&zelf, &vm.ctx.types.type_type) {
|
||||
if !pytype::isinstance(&zelf, &vm.ctx.types.type_type) {
|
||||
let actual_type = &zelf.class().name;
|
||||
return Err(vm.new_type_error(format!(
|
||||
"requires a 'type' object but received a '{}'",
|
||||
@@ -161,7 +161,7 @@ pub(crate) fn init(context: &PyContext) {
|
||||
}
|
||||
|
||||
pub fn not(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<bool> {
|
||||
if objtype::isinstance(obj, &vm.ctx.types.bool_type) {
|
||||
if pytype::isinstance(obj, &vm.ctx.types.bool_type) {
|
||||
let value = get_value(obj);
|
||||
Ok(!value)
|
||||
} else {
|
||||
@@ -12,11 +12,11 @@ use unic_ucd_category::GeneralCategory;
|
||||
use unic_ucd_ident::{is_xid_continue, is_xid_start};
|
||||
use unicode_casing::CharExt;
|
||||
|
||||
use super::objbytes::{PyBytes, PyBytesRef};
|
||||
use super::objdict::PyDict;
|
||||
use super::objint::{PyInt, PyIntRef};
|
||||
use super::objiter;
|
||||
use super::objtype::{self, PyTypeRef};
|
||||
use super::bytes::{PyBytes, PyBytesRef};
|
||||
use super::dict::PyDict;
|
||||
use super::int::{PyInt, PyIntRef};
|
||||
use super::iter;
|
||||
use super::pytype::{self, PyTypeRef};
|
||||
use crate::anystr::{self, adjust_indices, AnyStr, AnyStrContainer, AnyStrWrapper};
|
||||
use crate::exceptions::IntoPyException;
|
||||
use crate::format::{FormatSpec, FormatString, FromTemplate};
|
||||
@@ -122,7 +122,7 @@ impl PyStrIterator {
|
||||
let value = &*self.string.value;
|
||||
let start = self.position.load();
|
||||
if start == value.len() {
|
||||
return Err(objiter::new_stop_iteration(vm));
|
||||
return Err(iter::new_stop_iteration(vm));
|
||||
}
|
||||
let end = {
|
||||
let mut end = None;
|
||||
@@ -169,7 +169,7 @@ impl PyStrReverseIterator {
|
||||
let value = &*self.string.value;
|
||||
let end = self.position.load();
|
||||
if end == 0 {
|
||||
return Err(objiter::new_stop_iteration(vm));
|
||||
return Err(iter::new_stop_iteration(vm));
|
||||
}
|
||||
let start = {
|
||||
let mut start = None;
|
||||
@@ -241,7 +241,7 @@ impl PyStr {
|
||||
|
||||
#[pymethod(name = "__add__")]
|
||||
fn add(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<String> {
|
||||
if objtype::isinstance(&other, &vm.ctx.types.str_type) {
|
||||
if pytype::isinstance(&other, &vm.ctx.types.str_type) {
|
||||
Ok(self.value.py_add(borrow_value(&other)))
|
||||
} else {
|
||||
Err(vm.new_type_error(format!("Cannot add {} and {}", self, other)))
|
||||
@@ -6,8 +6,8 @@ https://github.com/python/cpython/blob/50b48572d9a90c5bb36e2bef6179548ea927a35a/
|
||||
|
||||
*/
|
||||
|
||||
use super::objstr::PyStrRef;
|
||||
use super::objtype::{self, PyType, PyTypeRef};
|
||||
use super::pystr::PyStrRef;
|
||||
use super::pytype::{self, PyType, PyTypeRef};
|
||||
use crate::function::OptionalArg;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IdProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
@@ -77,7 +77,7 @@ impl PySuper {
|
||||
};
|
||||
|
||||
// Check type argument:
|
||||
if !objtype::isinstance(typ.as_object(), &vm.ctx.types.type_type) {
|
||||
if !pytype::isinstance(typ.as_object(), &vm.ctx.types.type_type) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"super() argument 1 must be type, not {}",
|
||||
typ.class().name
|
||||
@@ -159,16 +159,16 @@ impl SlotDescriptor for PySuper {
|
||||
|
||||
fn supercheck(ty: PyTypeRef, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyTypeRef> {
|
||||
if let Ok(cls) = obj.clone().downcast::<PyType>() {
|
||||
if objtype::issubclass(&cls, &ty) {
|
||||
if pytype::issubclass(&cls, &ty) {
|
||||
return Ok(cls);
|
||||
}
|
||||
}
|
||||
if objtype::isinstance(&obj, &ty) {
|
||||
if pytype::isinstance(&obj, &ty) {
|
||||
return Ok(obj.clone_class());
|
||||
}
|
||||
let class_attr = vm.get_attribute(obj, "__class__")?;
|
||||
if let Ok(cls) = class_attr.downcast::<PyType>() {
|
||||
if !cls.is(&ty) && objtype::issubclass(&cls, &ty) {
|
||||
if !cls.is(&ty) && pytype::issubclass(&cls, &ty) {
|
||||
return Ok(cls);
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,16 @@ use crate::common::lock::PyRwLock;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fmt;
|
||||
|
||||
use super::objclassmethod::PyClassMethod;
|
||||
use super::objdict::PyDictRef;
|
||||
use super::objint::PyInt;
|
||||
use super::objlist::PyList;
|
||||
use super::objmappingproxy::PyMappingProxy;
|
||||
use super::objobject;
|
||||
use super::objstaticmethod::PyStaticMethod;
|
||||
use super::objstr::PyStrRef;
|
||||
use super::objtuple::PyTuple;
|
||||
use super::objweakref::PyWeak;
|
||||
use super::classmethod::PyClassMethod;
|
||||
use super::dict::PyDictRef;
|
||||
use super::int::PyInt;
|
||||
use super::list::PyList;
|
||||
use super::mappingproxy::PyMappingProxy;
|
||||
use super::object;
|
||||
use super::pystr::PyStrRef;
|
||||
use super::staticmethod::PyStaticMethod;
|
||||
use super::tuple::PyTuple;
|
||||
use super::weakref::PyWeak;
|
||||
use crate::function::{FuncArgs, KwArgs};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, IdProtocol, PyAttributes, PyClassImpl, PyContext, PyIterable, PyLease,
|
||||
@@ -584,7 +584,7 @@ fn subtype_get_dict(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
cls.name
|
||||
)))
|
||||
})?,
|
||||
None => objobject::object_get_dict(obj, vm)?.into_object(),
|
||||
None => object::object_get_dict(obj, vm)?.into_object(),
|
||||
};
|
||||
Ok(ret)
|
||||
}
|
||||
@@ -603,7 +603,7 @@ fn subtype_set_dict(obj: PyObjectRef, value: PyObjectRef, vm: &VirtualMachine) -
|
||||
)))
|
||||
})?;
|
||||
}
|
||||
None => objobject::object_set_dict(obj, PyDictRef::try_from_object(vm, value)?, vm)?,
|
||||
None => object::object_set_dict(obj, PyDictRef::try_from_object(vm, value)?, vm)?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -3,10 +3,10 @@ use num_bigint::{BigInt, Sign};
|
||||
use num_integer::Integer;
|
||||
use num_traits::{One, Signed, Zero};
|
||||
|
||||
use super::objint::{PyInt, PyIntRef};
|
||||
use super::objiter;
|
||||
use super::objslice::{PySlice, PySliceRef};
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::int::{PyInt, PyIntRef};
|
||||
use super::iter;
|
||||
use super::pytype::PyTypeRef;
|
||||
use super::slice::{PySlice, PySliceRef};
|
||||
|
||||
use crate::common::hash::PyHash;
|
||||
use crate::function::{FuncArgs, OptionalArg};
|
||||
@@ -119,9 +119,9 @@ impl PyRange {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_value(obj: &PyObjectRef) -> PyRange {
|
||||
obj.payload::<PyRange>().unwrap().clone()
|
||||
}
|
||||
// pub fn get_value(obj: &PyObjectRef) -> PyRange {
|
||||
// obj.payload::<PyRange>().unwrap().clone()
|
||||
// }
|
||||
|
||||
pub fn init(context: &PyContext) {
|
||||
PyRange::extend_class(context, &context.types.range_type);
|
||||
@@ -393,7 +393,7 @@ impl PyRangeIterator {
|
||||
if let Some(int) = self.range.get(&position) {
|
||||
Ok(int)
|
||||
} else {
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
use rustpython_common::rc::PyRc;
|
||||
use std::fmt;
|
||||
|
||||
use super::objiter;
|
||||
use super::objtype::{self, PyTypeRef};
|
||||
use super::iter;
|
||||
use super::pytype::{self, PyTypeRef};
|
||||
use crate::dictdatatype;
|
||||
use crate::function::{Args, OptionalArg};
|
||||
use crate::pyobject::{
|
||||
@@ -723,8 +723,8 @@ struct SetIterable {
|
||||
impl TryFromObject for SetIterable {
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
let class = obj.class();
|
||||
if objtype::issubclass(&class, &vm.ctx.types.set_type)
|
||||
|| objtype::issubclass(&class, &vm.ctx.types.frozenset_type)
|
||||
if pytype::issubclass(&class, &vm.ctx.types.set_type)
|
||||
|| pytype::issubclass(&class, &vm.ctx.types.frozenset_type)
|
||||
{
|
||||
// the class lease needs to be drop to be able to return the object
|
||||
drop(class);
|
||||
@@ -768,7 +768,7 @@ impl PySetIterator {
|
||||
let keys = self.dict.keys();
|
||||
let item = keys
|
||||
.get(index)
|
||||
.ok_or_else(|| objiter::new_stop_iteration(vm))?;
|
||||
.ok_or_else(|| iter::new_stop_iteration(vm))?;
|
||||
size_info.position += 1;
|
||||
self.size_info.store(size_info);
|
||||
return Ok(item.clone());
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef, PyValue, TypeProtocol,
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
// sliceobject.{h,c} in CPython
|
||||
|
||||
use super::objint::PyInt;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::int::PyInt;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::function::{FuncArgs, OptionalArg};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IntoPyObject, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef,
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::pyobject::{PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::slots::SlotDescriptor;
|
||||
use crate::vm::VirtualMachine;
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::frame::FrameRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{PyClassImpl, PyContext, PyRef, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
@@ -2,9 +2,9 @@ use crossbeam_utils::atomic::AtomicCell;
|
||||
use num_traits::ToPrimitive;
|
||||
use std::fmt;
|
||||
|
||||
use super::objint::PyIntRef;
|
||||
use super::objiter;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::int::PyIntRef;
|
||||
use super::iter;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::common::hash::PyHash;
|
||||
use crate::pyobject::{
|
||||
self, BorrowValue, Either, IdProtocol, IntoPyObject, PyArithmaticValue, PyClassImpl,
|
||||
@@ -302,7 +302,7 @@ impl PyTupleIterator {
|
||||
if let Some(obj) = self.tuple.borrow_value().get(pos) {
|
||||
Ok(obj.clone())
|
||||
} else {
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::objweakref::PyWeak;
|
||||
use super::pytype::PyTypeRef;
|
||||
use super::weakref::PyWeak;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::pyobject::{PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::common::hash::PyHash;
|
||||
use crate::function::{FuncArgs, OptionalArg};
|
||||
use crate::pyobject::{
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::objiter;
|
||||
use super::objtype::PyTypeRef;
|
||||
use super::iter;
|
||||
use super::pytype::PyTypeRef;
|
||||
use crate::function::Args;
|
||||
use crate::pyobject::{PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
@@ -24,7 +24,7 @@ impl PyZip {
|
||||
fn tp_new(cls: PyTypeRef, iterables: Args, vm: &VirtualMachine) -> PyResult<PyZipRef> {
|
||||
let iterators = iterables
|
||||
.into_iter()
|
||||
.map(|iterable| objiter::get_iter(vm, &iterable))
|
||||
.map(|iterable| iter::get_iter(vm, &iterable))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
PyZip { iterators }.into_ref_with_type(vm, cls)
|
||||
}
|
||||
@@ -32,12 +32,12 @@ impl PyZip {
|
||||
#[pymethod(name = "__next__")]
|
||||
fn next(&self, vm: &VirtualMachine) -> PyResult {
|
||||
if self.iterators.is_empty() {
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
} else {
|
||||
let next_objs = self
|
||||
.iterators
|
||||
.iter()
|
||||
.map(|iterator| objiter::call_next(vm, iterator))
|
||||
.map(|iterator| iter::call_next(vm, iterator))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok(vm.ctx.new_tuple(next_objs))
|
||||
+11
-11
@@ -4,17 +4,17 @@ use num_bigint::BigInt;
|
||||
use num_traits::ToPrimitive;
|
||||
|
||||
use crate::anystr::{self, AnyStr, AnyStrContainer, AnyStrWrapper};
|
||||
use crate::builtins::bytearray::PyByteArray;
|
||||
use crate::builtins::bytes::{PyBytes, PyBytesRef};
|
||||
use crate::builtins::int::{self, PyInt, PyIntRef};
|
||||
use crate::builtins::list::PyList;
|
||||
use crate::builtins::memory::PyMemoryView;
|
||||
use crate::builtins::pystr::{self, PyStr, PyStrRef};
|
||||
use crate::builtins::singletons::PyNoneRef;
|
||||
use crate::builtins::slice::PySliceRef;
|
||||
use crate::builtins::tuple::PyTuple;
|
||||
use crate::byteslike::try_bytes_like;
|
||||
use crate::function::{OptionalArg, OptionalOption};
|
||||
use crate::obj::objbytearray::PyByteArray;
|
||||
use crate::obj::objbytes::{PyBytes, PyBytesRef};
|
||||
use crate::obj::objint::{self, PyInt, PyIntRef};
|
||||
use crate::obj::objlist::PyList;
|
||||
use crate::obj::objmemory::PyMemoryView;
|
||||
use crate::obj::objsingletons::PyNoneRef;
|
||||
use crate::obj::objslice::PySliceRef;
|
||||
use crate::obj::objstr::{self, PyStr, PyStrRef};
|
||||
use crate::obj::objtuple::PyTuple;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, PyComparisonValue, PyIterable, PyIterator, PyObjectRef, PyResult,
|
||||
TryFromObject, TypeProtocol,
|
||||
@@ -91,7 +91,7 @@ impl ByteInnerNewOptions {
|
||||
// Handle bytes(string, encoding[, errors])
|
||||
if let OptionalArg::Present(enc) = self.encoding {
|
||||
let bytes =
|
||||
objstr::encode_string(s, Some(enc), self.errors.into_option(), vm)?;
|
||||
pystr::encode_string(s, Some(enc), self.errors.into_option(), vm)?;
|
||||
Ok(PyBytesInner {
|
||||
elements: bytes.borrow_value().to_vec(),
|
||||
})
|
||||
@@ -107,7 +107,7 @@ impl ByteInnerNewOptions {
|
||||
} else {
|
||||
let value = match_class!(match obj {
|
||||
i @ PyInt => {
|
||||
let size = objint::get_value(&i.into_object())
|
||||
let size = int::get_value(&i.into_object())
|
||||
.to_isize()
|
||||
.ok_or_else(|| {
|
||||
vm.new_overflow_error(
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
use crate::builtins::memory::{try_buffer_from_object, BufferRef};
|
||||
use crate::common::borrow::{BorrowedValue, BorrowedValueMut};
|
||||
use crate::obj::objmemory::{try_buffer_from_object, BufferRef};
|
||||
use crate::pyobject::{BorrowValue, PyObjectRef, PyResult, TryFromObject};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
|
||||
+20
-20
@@ -1,7 +1,7 @@
|
||||
use crate::builtins::{float, int, pystr, pytype, tuple};
|
||||
/// Implementation of Printf-Style string formatting
|
||||
/// [https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting]
|
||||
use crate::format::get_num_digits;
|
||||
use crate::obj::{objfloat, objint, objstr, objtuple, objtype};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, ItemProtocol, PyObjectRef, PyResult, TryFromObject, TypeProtocol,
|
||||
};
|
||||
@@ -315,13 +315,13 @@ impl CFormatSpec {
|
||||
))
|
||||
};
|
||||
match_class!(match &obj {
|
||||
ref i @ objint::PyInt => {
|
||||
ref i @ int::PyInt => {
|
||||
self.format_number(i.borrow_value())
|
||||
}
|
||||
// TODO: if guards for match_class
|
||||
ref f @ objfloat::PyFloat => {
|
||||
ref f @ float::PyFloat => {
|
||||
if let CNumberType::Decimal = number_type {
|
||||
self.format_number(&objfloat::try_bigint(f.to_f64(), vm)?)
|
||||
self.format_number(&float::try_bigint(f.to_f64(), vm)?)
|
||||
} else {
|
||||
return Err(err());
|
||||
}
|
||||
@@ -330,7 +330,7 @@ impl CFormatSpec {
|
||||
})
|
||||
}
|
||||
CFormatType::Float(_) => {
|
||||
let value = objfloat::try_float(&obj, vm)?.ok_or_else(|| {
|
||||
let value = float::try_float(&obj, vm)?.ok_or_else(|| {
|
||||
vm.new_type_error(format!(
|
||||
"%{} format: an floating point or integer is required, not {}",
|
||||
self.format_char,
|
||||
@@ -342,16 +342,16 @@ impl CFormatSpec {
|
||||
}
|
||||
CFormatType::Character => {
|
||||
let ch = {
|
||||
if objtype::isinstance(&obj, &vm.ctx.types.int_type) {
|
||||
if pytype::isinstance(&obj, &vm.ctx.types.int_type) {
|
||||
// BigInt truncation is fine in this case because only the unicode range is relevant
|
||||
objint::get_value(&obj)
|
||||
int::get_value(&obj)
|
||||
.to_u32()
|
||||
.and_then(std::char::from_u32)
|
||||
.ok_or_else(|| {
|
||||
vm.new_overflow_error("%c arg not in range(0x110000)".to_owned())
|
||||
})
|
||||
} else if objtype::isinstance(&obj, &vm.ctx.types.str_type) {
|
||||
let s = objstr::borrow_value(&obj);
|
||||
} else if pytype::isinstance(&obj, &vm.ctx.types.str_type) {
|
||||
let s = pystr::borrow_value(&obj);
|
||||
let num_chars = s.chars().count();
|
||||
if num_chars != 1 {
|
||||
Err(vm.new_type_error("%c requires int or char".to_owned()))
|
||||
@@ -435,11 +435,11 @@ impl CFormatString {
|
||||
Some(CFormatQuantity::FromValuesTuple) => match elements.next() {
|
||||
Some(width_obj) => {
|
||||
tuple_index += 1;
|
||||
if !objtype::isinstance(&width_obj, &vm.ctx.types.int_type) {
|
||||
if !pytype::isinstance(&width_obj, &vm.ctx.types.int_type) {
|
||||
Err(vm.new_type_error("* wants int".to_owned()))
|
||||
} else {
|
||||
let i = objint::get_value(&width_obj);
|
||||
let i = objint::try_to_primitive::<isize>(i, vm)? as usize;
|
||||
let i = int::get_value(&width_obj);
|
||||
let i = int::try_to_primitive::<isize>(i, vm)? as usize;
|
||||
*q = Some(CFormatQuantity::Amount(i));
|
||||
Ok(tuple_index)
|
||||
}
|
||||
@@ -469,16 +469,16 @@ impl CFormatString {
|
||||
.all(|(_, part)| CFormatPart::has_key(part));
|
||||
|
||||
let values = if mapping_required {
|
||||
if !objtype::isinstance(&values_obj, &vm.ctx.types.dict_type) {
|
||||
if !pytype::isinstance(&values_obj, &vm.ctx.types.dict_type) {
|
||||
return Err(vm.new_type_error("format requires a mapping".to_owned()));
|
||||
}
|
||||
values_obj.clone()
|
||||
} else {
|
||||
// check for only literal parts, in which case only dict or empty tuple is allowed
|
||||
if num_specifiers == 0
|
||||
&& !(objtype::isinstance(&values_obj, &vm.ctx.types.tuple_type)
|
||||
&& objtuple::get_value(&values_obj).is_empty())
|
||||
&& !objtype::isinstance(&values_obj, &vm.ctx.types.dict_type)
|
||||
&& !(pytype::isinstance(&values_obj, &vm.ctx.types.tuple_type)
|
||||
&& tuple::get_value(&values_obj).is_empty())
|
||||
&& !pytype::isinstance(&values_obj, &vm.ctx.types.dict_type)
|
||||
{
|
||||
return Err(vm.new_type_error(
|
||||
"not all arguments converted during string formatting".to_owned(),
|
||||
@@ -486,7 +486,7 @@ impl CFormatString {
|
||||
}
|
||||
|
||||
// convert `values_obj` to a new tuple if it's not a tuple
|
||||
if !objtype::isinstance(&values_obj, &vm.ctx.types.tuple_type) {
|
||||
if !pytype::isinstance(&values_obj, &vm.ctx.types.tuple_type) {
|
||||
vm.ctx.new_tuple(vec![values_obj.clone()])
|
||||
} else {
|
||||
values_obj.clone()
|
||||
@@ -504,7 +504,7 @@ impl CFormatString {
|
||||
values.get_item(key, vm)?
|
||||
}
|
||||
None => {
|
||||
let mut elements = objtuple::get_value(&values)
|
||||
let mut elements = tuple::get_value(&values)
|
||||
.to_vec()
|
||||
.into_iter()
|
||||
.skip(tuple_index);
|
||||
@@ -541,8 +541,8 @@ impl CFormatString {
|
||||
}
|
||||
|
||||
// check that all arguments were converted
|
||||
if (!mapping_required && objtuple::get_value(&values).get(tuple_index).is_some())
|
||||
&& !objtype::isinstance(&values_obj, &vm.ctx.types.dict_type)
|
||||
if (!mapping_required && tuple::get_value(&values).get(tuple_index).is_some())
|
||||
&& !pytype::isinstance(&values_obj, &vm.ctx.types.dict_type)
|
||||
{
|
||||
return Err(vm.new_type_error(
|
||||
"not all arguments converted during string formatting".to_owned(),
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
use crate::builtins::pytype::{self, PyTypeRef};
|
||||
use crate::exceptions::{self, PyBaseExceptionRef};
|
||||
use crate::frame::{ExecutionResult, FrameRef};
|
||||
use crate::obj::objtype::{self, PyTypeRef};
|
||||
use crate::pyobject::{PyObjectRef, PyResult};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
@@ -98,13 +98,13 @@ impl Coro {
|
||||
match result {
|
||||
Ok(exec_res) => self.variant.exec_result(exec_res, vm),
|
||||
Err(e) => {
|
||||
if objtype::isinstance(&e, &vm.ctx.exceptions.stop_iteration) {
|
||||
if pytype::isinstance(&e, &vm.ctx.exceptions.stop_iteration) {
|
||||
let err = vm
|
||||
.new_runtime_error(format!("{} raised StopIteration", self.variant.name()));
|
||||
err.set_cause(Some(e));
|
||||
Err(err)
|
||||
} else if self.variant == Variant::AsyncGen
|
||||
&& objtype::isinstance(&e, &vm.ctx.exceptions.stop_async_iteration)
|
||||
&& pytype::isinstance(&e, &vm.ctx.exceptions.stop_async_iteration)
|
||||
{
|
||||
let err = vm
|
||||
.new_runtime_error("async generator raised StopAsyncIteration".to_owned());
|
||||
@@ -171,5 +171,5 @@ impl Coro {
|
||||
}
|
||||
|
||||
pub fn is_gen_exit(exc: &PyBaseExceptionRef, vm: &VirtualMachine) -> bool {
|
||||
objtype::isinstance(exc, &vm.ctx.exceptions.generator_exit)
|
||||
pytype::isinstance(exc, &vm.ctx.exceptions.generator_exit)
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::builtins::pystr::{PyStr, PyStrRef};
|
||||
/// Ordered dictionary implementation.
|
||||
/// Inspired by: https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html
|
||||
/// And: https://www.youtube.com/watch?v=p33CVV29OG8
|
||||
/// And: http://code.activestate.com/recipes/578375/
|
||||
use crate::common::lock::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard};
|
||||
use crate::obj::objstr::{PyStr, PyStrRef};
|
||||
use crate::pyobject::{BorrowValue, IdProtocol, IntoPyObject, PyObjectRef, PyResult};
|
||||
use crate::vm::VirtualMachine;
|
||||
use rustpython_common::hash;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::builtins::pystr::{PyStr, PyStrRef};
|
||||
use crate::builtins::pytype::{self, PyType, PyTypeRef};
|
||||
use crate::builtins::singletons::{PyNone, PyNoneRef};
|
||||
use crate::builtins::traceback::PyTracebackRef;
|
||||
use crate::builtins::tuple::{PyTuple, PyTupleRef};
|
||||
use crate::common::lock::PyRwLock;
|
||||
use crate::function::FuncArgs;
|
||||
use crate::obj::objsingletons::{PyNone, PyNoneRef};
|
||||
use crate::obj::objstr::{PyStr, PyStrRef};
|
||||
use crate::obj::objtraceback::PyTracebackRef;
|
||||
use crate::obj::objtuple::{PyTuple, PyTupleRef};
|
||||
use crate::obj::objtype::{self, PyType, PyTypeRef};
|
||||
use crate::py_io::{self, Write};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IntoPyObject, PyClassDef, PyClassImpl, PyContext, PyIterable, PyObjectRef, PyRef,
|
||||
@@ -303,7 +303,7 @@ impl TryFromObject for ExceptionCtor {
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
obj.downcast::<PyType>()
|
||||
.and_then(|cls| {
|
||||
if objtype::issubclass(&cls, &vm.ctx.exceptions.base_exception_type) {
|
||||
if pytype::issubclass(&cls, &vm.ctx.exceptions.base_exception_type) {
|
||||
Ok(Self::Class(cls))
|
||||
} else {
|
||||
Err(cls.into_object())
|
||||
@@ -352,7 +352,7 @@ impl ExceptionCtor {
|
||||
// if the "type" is an instance and the value isn't, use the "type"
|
||||
(Self::Instance(exc), None) => Ok(exc),
|
||||
// if the value is an instance of the type, use the instance value
|
||||
(Self::Class(cls), Some(exc)) if objtype::isinstance(&exc, &cls) => Ok(exc),
|
||||
(Self::Class(cls), Some(exc)) if pytype::isinstance(&exc, &cls) => Ok(exc),
|
||||
// otherwise; construct an exception of the type using the value as args
|
||||
(Self::Class(cls), _) => {
|
||||
let args = match_class!(match value {
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
use crate::builtins::{pystr, pytype};
|
||||
use crate::exceptions::{IntoPyException, PyBaseExceptionRef};
|
||||
use crate::function::FuncArgs;
|
||||
use crate::obj::{objstr, objtype};
|
||||
use crate::pyobject::{ItemProtocol, PyObjectRef, PyResult, TypeProtocol};
|
||||
use crate::vm::VirtualMachine;
|
||||
use itertools::{Itertools, PeekingNext};
|
||||
@@ -830,7 +830,7 @@ impl FormatString {
|
||||
|
||||
let value =
|
||||
call_object_format(vm, argument, *preconversion_spec, &format_spec)?;
|
||||
objstr::clone_value(&value)
|
||||
pystr::clone_value(&value)
|
||||
}
|
||||
FormatPart::Literal(literal) => literal.clone(),
|
||||
};
|
||||
@@ -901,7 +901,7 @@ fn call_object_format(
|
||||
None => argument,
|
||||
};
|
||||
let result = vm.call_method(&argument, "__format__", (format_spec,))?;
|
||||
if !objtype::isinstance(&result, &vm.ctx.types.str_type) {
|
||||
if !pytype::isinstance(&result, &vm.ctx.types.str_type) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"__format__ must return a str, not {}",
|
||||
&result.class().name
|
||||
|
||||
+32
-34
@@ -4,23 +4,23 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use indexmap::IndexMap;
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::builtins::asyncgenerator::PyAsyncGenWrappedValue;
|
||||
use crate::builtins::builtin_isinstance;
|
||||
use crate::builtins::code::PyCodeRef;
|
||||
use crate::builtins::coroutine::PyCoroutine;
|
||||
use crate::builtins::dict::{PyDict, PyDictRef};
|
||||
use crate::builtins::generator::PyGenerator;
|
||||
use crate::builtins::pystr::{self, PyStr, PyStrRef};
|
||||
use crate::builtins::pytype::{self, PyTypeRef};
|
||||
use crate::builtins::slice::PySlice;
|
||||
use crate::builtins::traceback::PyTraceback;
|
||||
use crate::builtins::tuple::PyTuple;
|
||||
use crate::builtins::{iter, list, pybool, set};
|
||||
use crate::bytecode;
|
||||
use crate::common::lock::PyMutex;
|
||||
use crate::coroutine::Coro;
|
||||
use crate::exceptions::{self, ExceptionCtor, PyBaseExceptionRef};
|
||||
use crate::function::FuncArgs;
|
||||
use crate::obj::objasyncgenerator::PyAsyncGenWrappedValue;
|
||||
use crate::obj::objcode::PyCodeRef;
|
||||
use crate::obj::objcoroutine::PyCoroutine;
|
||||
use crate::obj::objdict::{PyDict, PyDictRef};
|
||||
use crate::obj::objgenerator::PyGenerator;
|
||||
use crate::obj::objslice::PySlice;
|
||||
use crate::obj::objstr::{self, PyStr, PyStrRef};
|
||||
use crate::obj::objtraceback::PyTraceback;
|
||||
use crate::obj::objtuple::PyTuple;
|
||||
use crate::obj::objtype::{self, PyTypeRef};
|
||||
use crate::obj::{objbool, objiter, objlist, objset};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IdProtocol, ItemProtocol, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
|
||||
TypeProtocol,
|
||||
@@ -116,8 +116,8 @@ impl ExecutionResult {
|
||||
match res {
|
||||
Ok(val) => Ok(ExecutionResult::Yield(val)),
|
||||
Err(err) => {
|
||||
if objtype::isinstance(&err, &vm.ctx.exceptions.stop_iteration) {
|
||||
objiter::stop_iter_value(vm, &err).map(ExecutionResult::Return)
|
||||
if pytype::isinstance(&err, &vm.ctx.exceptions.stop_iteration) {
|
||||
iter::stop_iter_value(vm, &err).map(ExecutionResult::Return)
|
||||
} else {
|
||||
Err(err)
|
||||
}
|
||||
@@ -313,7 +313,7 @@ impl ExecutingFrame<'_> {
|
||||
res.or_else(|err| {
|
||||
self.pop_value();
|
||||
self.lasti.fetch_add(1, Ordering::Relaxed);
|
||||
let val = objiter::stop_iter_value(vm, &err)?;
|
||||
let val = iter::stop_iter_value(vm, &err)?;
|
||||
self._send(coro, val, vm)
|
||||
})
|
||||
.map(ExecutionResult::Yield)
|
||||
@@ -386,7 +386,7 @@ impl ExecutingFrame<'_> {
|
||||
let s = self
|
||||
.pop_multiple(*size)
|
||||
.into_iter()
|
||||
.map(|pyobj| objstr::clone_value(&pyobj))
|
||||
.map(|pyobj| pystr::clone_value(&pyobj))
|
||||
.collect::<String>();
|
||||
let str_obj = vm.ctx.new_str(s);
|
||||
self.push_value(str_obj);
|
||||
@@ -422,13 +422,13 @@ impl ExecutingFrame<'_> {
|
||||
bytecode::Instruction::ListAppend { i } => {
|
||||
let list_obj = self.nth_value(*i);
|
||||
let item = self.pop_value();
|
||||
objlist::PyListRef::try_from_object(vm, list_obj)?.append(item);
|
||||
list::PyListRef::try_from_object(vm, list_obj)?.append(item);
|
||||
Ok(None)
|
||||
}
|
||||
bytecode::Instruction::SetAdd { i } => {
|
||||
let set_obj = self.nth_value(*i);
|
||||
let item = self.pop_value();
|
||||
objset::PySetRef::try_from_object(vm, set_obj)?.add(item, vm)?;
|
||||
set::PySetRef::try_from_object(vm, set_obj)?.add(item, vm)?;
|
||||
Ok(None)
|
||||
}
|
||||
bytecode::Instruction::MapAdd { i } => {
|
||||
@@ -564,7 +564,7 @@ impl ExecutingFrame<'_> {
|
||||
_ => panic!("WithCleanupFinish expects a FinallyHandler block on stack"),
|
||||
};
|
||||
|
||||
let suppress_exception = objbool::boolval(vm, self.pop_value())?;
|
||||
let suppress_exception = pybool::boolval(vm, self.pop_value())?;
|
||||
if suppress_exception {
|
||||
// suppress exception
|
||||
Ok(None)
|
||||
@@ -580,7 +580,7 @@ impl ExecutingFrame<'_> {
|
||||
}
|
||||
bytecode::Instruction::GetIter => {
|
||||
let iterated_obj = self.pop_value();
|
||||
let iter_obj = objiter::get_iter(vm, &iterated_obj)?;
|
||||
let iter_obj = iter::get_iter(vm, &iterated_obj)?;
|
||||
self.push_value(iter_obj);
|
||||
Ok(None)
|
||||
}
|
||||
@@ -627,7 +627,7 @@ impl ExecutingFrame<'_> {
|
||||
}
|
||||
bytecode::Instruction::JumpIfTrue { target } => {
|
||||
let obj = self.pop_value();
|
||||
let value = objbool::boolval(vm, obj)?;
|
||||
let value = pybool::boolval(vm, obj)?;
|
||||
if value {
|
||||
self.jump(*target);
|
||||
}
|
||||
@@ -636,7 +636,7 @@ impl ExecutingFrame<'_> {
|
||||
|
||||
bytecode::Instruction::JumpIfFalse { target } => {
|
||||
let obj = self.pop_value();
|
||||
let value = objbool::boolval(vm, obj)?;
|
||||
let value = pybool::boolval(vm, obj)?;
|
||||
if !value {
|
||||
self.jump(*target);
|
||||
}
|
||||
@@ -645,7 +645,7 @@ impl ExecutingFrame<'_> {
|
||||
|
||||
bytecode::Instruction::JumpIfTrueOrPop { target } => {
|
||||
let obj = self.last_value();
|
||||
let value = objbool::boolval(vm, obj)?;
|
||||
let value = pybool::boolval(vm, obj)?;
|
||||
if value {
|
||||
self.jump(*target);
|
||||
} else {
|
||||
@@ -656,7 +656,7 @@ impl ExecutingFrame<'_> {
|
||||
|
||||
bytecode::Instruction::JumpIfFalseOrPop { target } => {
|
||||
let obj = self.last_value();
|
||||
let value = objbool::boolval(vm, obj)?;
|
||||
let value = pybool::boolval(vm, obj)?;
|
||||
if !value {
|
||||
self.jump(*target);
|
||||
} else {
|
||||
@@ -1063,7 +1063,7 @@ impl ExecutingFrame<'_> {
|
||||
let kwarg_names = vm
|
||||
.extract_elements(&kwarg_names)?
|
||||
.iter()
|
||||
.map(|pyobj| objstr::clone_value(pyobj))
|
||||
.map(|pyobj| pystr::clone_value(pyobj))
|
||||
.collect();
|
||||
FuncArgs::with_kwargs_names(args, kwarg_names)
|
||||
}
|
||||
@@ -1075,11 +1075,9 @@ impl ExecutingFrame<'_> {
|
||||
})?;
|
||||
let mut kwargs = IndexMap::new();
|
||||
for (key, value) in kw_dict.into_iter() {
|
||||
let key =
|
||||
key.payload_if_subclass::<objstr::PyStr>(vm)
|
||||
.ok_or_else(|| {
|
||||
vm.new_type_error("keywords must be strings".to_owned())
|
||||
})?;
|
||||
let key = key.payload_if_subclass::<pystr::PyStr>(vm).ok_or_else(|| {
|
||||
vm.new_type_error("keywords must be strings".to_owned())
|
||||
})?;
|
||||
kwargs.insert(key.borrow_value().to_owned(), value);
|
||||
}
|
||||
kwargs
|
||||
@@ -1148,7 +1146,7 @@ impl ExecutingFrame<'_> {
|
||||
fn _send(&self, coro: PyObjectRef, val: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
match self.builtin_coro(&coro) {
|
||||
Some(coro) => coro.send(val, vm),
|
||||
None if vm.is_none(&val) => objiter::call_next(vm, &coro),
|
||||
None if vm.is_none(&val) => iter::call_next(vm, &coro),
|
||||
None => vm.call_method(&coro, "send", (val,)),
|
||||
}
|
||||
}
|
||||
@@ -1222,7 +1220,7 @@ impl ExecutingFrame<'_> {
|
||||
/// The top of stack contains the iterator, lets push it forward
|
||||
fn execute_for_iter(&mut self, vm: &VirtualMachine, target: bytecode::Label) -> FrameResult {
|
||||
let top_of_stack = self.last_value();
|
||||
let next_obj = objiter::get_next_object(vm, &top_of_stack);
|
||||
let next_obj = iter::get_next_object(vm, &top_of_stack);
|
||||
|
||||
// Check the next object:
|
||||
match next_obj {
|
||||
@@ -1362,7 +1360,7 @@ impl ExecutingFrame<'_> {
|
||||
bytecode::UnaryOperator::Plus => vm.call_method(&a, "__pos__", ())?,
|
||||
bytecode::UnaryOperator::Invert => vm.call_method(&a, "__invert__", ())?,
|
||||
bytecode::UnaryOperator::Not => {
|
||||
let value = objbool::boolval(vm, a)?;
|
||||
let value = pybool::boolval(vm, a)?;
|
||||
vm.ctx.new_bool(!value)
|
||||
}
|
||||
};
|
||||
@@ -1381,7 +1379,7 @@ impl ExecutingFrame<'_> {
|
||||
haystack: PyObjectRef,
|
||||
) -> PyResult<bool> {
|
||||
let found = vm._membership(haystack, needle)?;
|
||||
Ok(objbool::boolval(vm, found)?)
|
||||
Ok(pybool::boolval(vm, found)?)
|
||||
}
|
||||
|
||||
fn _not_in(
|
||||
@@ -1391,7 +1389,7 @@ impl ExecutingFrame<'_> {
|
||||
haystack: PyObjectRef,
|
||||
) -> PyResult<bool> {
|
||||
let found = vm._membership(haystack, needle)?;
|
||||
Ok(!objbool::boolval(vm, found)?)
|
||||
Ok(!pybool::boolval(vm, found)?)
|
||||
}
|
||||
|
||||
fn _is(&self, a: PyObjectRef, b: PyObjectRef) -> bool {
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
use self::OptionalArg::*;
|
||||
use crate::builtins::pytype::{isinstance, PyTypeRef};
|
||||
use crate::builtins::tuple::PyTupleRef;
|
||||
use crate::exceptions::PyBaseExceptionRef;
|
||||
use crate::obj::objtuple::PyTupleRef;
|
||||
use crate::obj::objtype::{isinstance, PyTypeRef};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IntoPyObject, IntoPyResult, PyObjectRef, PyRef, PyResult, PyThreadingConstraint,
|
||||
PyValue, TryFromObject, TypeProtocol,
|
||||
|
||||
+5
-5
@@ -3,10 +3,10 @@
|
||||
*/
|
||||
use rand::Rng;
|
||||
|
||||
use crate::builtins::traceback::{PyTraceback, PyTracebackRef};
|
||||
use crate::builtins::{code, list, pytype};
|
||||
use crate::bytecode::CodeObject;
|
||||
use crate::exceptions::PyBaseExceptionRef;
|
||||
use crate::obj::objtraceback::{PyTraceback, PyTracebackRef};
|
||||
use crate::obj::{objcode, objlist, objtype};
|
||||
use crate::pyobject::{ItemProtocol, PyResult, PyValue, TryFromObject};
|
||||
use crate::scope::Scope;
|
||||
use crate::version::get_git_revision;
|
||||
@@ -47,7 +47,7 @@ pub(crate) fn init_importlib(
|
||||
let zipimport = vm.import("zipimport", &[], 0)?;
|
||||
let zipimporter = vm.get_attribute(zipimport, "zipimporter")?;
|
||||
let path_hooks = vm.get_attribute(vm.sys_module.clone(), "path_hooks")?;
|
||||
let path_hooks = objlist::PyListRef::try_from_object(vm, path_hooks)?;
|
||||
let path_hooks = list::PyListRef::try_from_object(vm, path_hooks)?;
|
||||
path_hooks.insert(0, zipimporter);
|
||||
Ok(())
|
||||
})();
|
||||
@@ -122,7 +122,7 @@ pub fn import_codeobj(
|
||||
|
||||
// Execute main code in module:
|
||||
vm.run_code_obj(
|
||||
objcode::PyCode::new(code_obj).into_ref(vm),
|
||||
code::PyCode::new(code_obj).into_ref(vm),
|
||||
Scope::with_builtins(None, attrs, vm),
|
||||
)?;
|
||||
Ok(module)
|
||||
@@ -174,7 +174,7 @@ pub fn remove_importlib_frames(
|
||||
vm: &VirtualMachine,
|
||||
exc: &PyBaseExceptionRef,
|
||||
) -> PyBaseExceptionRef {
|
||||
let always_trim = objtype::isinstance(exc, &vm.ctx.exceptions.import_error);
|
||||
let always_trim = pytype::isinstance(exc, &vm.ctx.exceptions.import_error);
|
||||
|
||||
if let Some(tb) = exc.traceback() {
|
||||
let trimmed_tb = remove_importlib_frames_inner(vm, Some(tb), always_trim).0;
|
||||
|
||||
+1
-2
@@ -44,7 +44,7 @@ pub use rustpython_derive::*;
|
||||
pub mod macros;
|
||||
|
||||
mod anystr;
|
||||
mod builtins;
|
||||
pub mod builtins;
|
||||
mod bytesinner;
|
||||
pub mod byteslike;
|
||||
pub mod cformat;
|
||||
@@ -58,7 +58,6 @@ pub mod frame;
|
||||
mod frozen;
|
||||
pub mod function;
|
||||
pub mod import;
|
||||
pub mod obj;
|
||||
mod py_io;
|
||||
pub mod py_serde;
|
||||
pub mod pyobject;
|
||||
|
||||
+4
-4
@@ -97,8 +97,8 @@ macro_rules! py_namespace {
|
||||
/// use num_traits::Zero;
|
||||
///
|
||||
/// use rustpython_vm::match_class;
|
||||
/// use rustpython_vm::obj::objfloat::PyFloat;
|
||||
/// use rustpython_vm::obj::objint::PyInt;
|
||||
/// use rustpython_vm::builtins::PyFloat;
|
||||
/// use rustpython_vm::builtins::PyInt;
|
||||
/// use rustpython_vm::pyobject::PyValue;
|
||||
///
|
||||
/// # rustpython_vm::Interpreter::default().enter(|vm| {
|
||||
@@ -122,8 +122,8 @@ macro_rules! py_namespace {
|
||||
/// use num_traits::Zero;
|
||||
///
|
||||
/// use rustpython_vm::match_class;
|
||||
/// use rustpython_vm::obj::objfloat::PyFloat;
|
||||
/// use rustpython_vm::obj::objint::PyInt;
|
||||
/// use rustpython_vm::builtins::PyFloat;
|
||||
/// use rustpython_vm::builtins::PyInt;
|
||||
/// use rustpython_vm::pyobject::{PyValue, BorrowValue};
|
||||
///
|
||||
/// # rustpython_vm::Interpreter::default().enter(|vm| {
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
//! This package contains the python basic/builtin types
|
||||
|
||||
pub mod objasyncgenerator;
|
||||
pub mod objbool;
|
||||
pub mod objbuiltinfunc;
|
||||
pub mod objbytearray;
|
||||
pub mod objbytes;
|
||||
pub mod objclassmethod;
|
||||
pub mod objcode;
|
||||
pub mod objcomplex;
|
||||
pub mod objcoroutine;
|
||||
pub mod objdict;
|
||||
pub mod objenumerate;
|
||||
pub mod objfilter;
|
||||
pub mod objfloat;
|
||||
pub mod objframe;
|
||||
pub mod objfunction;
|
||||
pub mod objgenerator;
|
||||
pub mod objgetset;
|
||||
pub mod objint;
|
||||
pub mod objiter;
|
||||
pub mod objlist;
|
||||
pub mod objmap;
|
||||
pub mod objmappingproxy;
|
||||
pub mod objmemory;
|
||||
pub mod objmodule;
|
||||
pub mod objnamespace;
|
||||
pub mod objobject;
|
||||
pub mod objproperty;
|
||||
pub mod objrange;
|
||||
pub mod objset;
|
||||
pub mod objsingletons;
|
||||
pub mod objslice;
|
||||
pub mod objstaticmethod;
|
||||
pub mod objstr;
|
||||
pub mod objsuper;
|
||||
pub mod objtraceback;
|
||||
pub mod objtuple;
|
||||
pub mod objtype;
|
||||
pub mod objweakproxy;
|
||||
pub mod objweakref;
|
||||
pub mod objzip;
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
use crate::builtins::bytes::PyBytes;
|
||||
use crate::builtins::pystr::PyStr;
|
||||
use crate::exceptions::PyBaseExceptionRef;
|
||||
use crate::obj::objbytes::PyBytes;
|
||||
use crate::obj::objstr::PyStr;
|
||||
use crate::pyobject::{BorrowValue, PyObjectRef, PyResult};
|
||||
use crate::VirtualMachine;
|
||||
use std::{fmt, io};
|
||||
|
||||
+11
-12
@@ -3,9 +3,8 @@ use num_traits::sign::Signed;
|
||||
use serde::de::{DeserializeSeed, Visitor};
|
||||
use serde::ser::{Serialize, SerializeMap, SerializeSeq};
|
||||
|
||||
use crate::obj::{
|
||||
objbool, objdict::PyDictRef, objfloat, objint, objlist::PyList, objstr, objtuple::PyTuple,
|
||||
objtype,
|
||||
use crate::builtins::{
|
||||
dict::PyDictRef, float, int, list::PyList, pybool, pystr, pytype, tuple::PyTuple,
|
||||
};
|
||||
use crate::pyobject::{BorrowValue, ItemProtocol, PyObjectRef, TypeProtocol};
|
||||
use crate::VirtualMachine;
|
||||
@@ -66,14 +65,14 @@ impl<'s> serde::Serialize for PyObjectSerializer<'s> {
|
||||
}
|
||||
seq.end()
|
||||
};
|
||||
if objtype::isinstance(self.pyobject, &self.vm.ctx.types.str_type) {
|
||||
serializer.serialize_str(objstr::borrow_value(&self.pyobject))
|
||||
} else if objtype::isinstance(self.pyobject, &self.vm.ctx.types.float_type) {
|
||||
serializer.serialize_f64(objfloat::get_value(self.pyobject))
|
||||
} else if objtype::isinstance(self.pyobject, &self.vm.ctx.types.bool_type) {
|
||||
serializer.serialize_bool(objbool::get_value(self.pyobject))
|
||||
} else if objtype::isinstance(self.pyobject, &self.vm.ctx.types.int_type) {
|
||||
let v = objint::get_value(self.pyobject);
|
||||
if pytype::isinstance(self.pyobject, &self.vm.ctx.types.str_type) {
|
||||
serializer.serialize_str(pystr::borrow_value(&self.pyobject))
|
||||
} else if pytype::isinstance(self.pyobject, &self.vm.ctx.types.float_type) {
|
||||
serializer.serialize_f64(float::get_value(self.pyobject))
|
||||
} else if pytype::isinstance(self.pyobject, &self.vm.ctx.types.bool_type) {
|
||||
serializer.serialize_bool(pybool::get_value(self.pyobject))
|
||||
} else if pytype::isinstance(self.pyobject, &self.vm.ctx.types.int_type) {
|
||||
let v = int::get_value(self.pyobject);
|
||||
let int_too_large = || serde::ser::Error::custom("int too large to serialize");
|
||||
// TODO: serialize BigInt when it does not fit into i64
|
||||
// BigInt implements serialization to a tuple of sign and a list of u32s,
|
||||
@@ -88,7 +87,7 @@ impl<'s> serde::Serialize for PyObjectSerializer<'s> {
|
||||
serialize_seq_elements(serializer, &list.borrow_value())
|
||||
} else if let Some(tuple) = self.pyobject.payload_if_subclass::<PyTuple>(self.vm) {
|
||||
serialize_seq_elements(serializer, tuple.borrow_value())
|
||||
} else if objtype::isinstance(self.pyobject, &self.vm.ctx.types.dict_type) {
|
||||
} else if pytype::isinstance(self.pyobject, &self.vm.ctx.types.dict_type) {
|
||||
let dict: PyDictRef = self.pyobject.clone().downcast().unwrap();
|
||||
let pairs: Vec<_> = dict.into_iter().collect();
|
||||
let mut map = serializer.serialize_map(Some(pairs.len()))?;
|
||||
|
||||
+41
-49
@@ -8,31 +8,31 @@ use num_bigint::BigInt;
|
||||
use num_complex::Complex64;
|
||||
use num_traits::ToPrimitive;
|
||||
|
||||
use crate::builtins::builtinfunc::PyFuncDef;
|
||||
use crate::builtins::bytearray;
|
||||
use crate::builtins::bytes;
|
||||
use crate::builtins::code;
|
||||
use crate::builtins::code::PyCodeRef;
|
||||
use crate::builtins::complex::PyComplex;
|
||||
use crate::builtins::dict::{PyDict, PyDictRef};
|
||||
use crate::builtins::float::PyFloat;
|
||||
use crate::builtins::function::{PyBoundMethod, PyFunction};
|
||||
use crate::builtins::getset::{IntoPyGetterFunc, IntoPySetterFunc, PyGetSet};
|
||||
use crate::builtins::int::{PyInt, PyIntRef};
|
||||
use crate::builtins::iter;
|
||||
use crate::builtins::list::PyList;
|
||||
use crate::builtins::namespace::PyNamespace;
|
||||
use crate::builtins::object;
|
||||
use crate::builtins::pystr;
|
||||
use crate::builtins::pytype::{self, PyType, PyTypeRef};
|
||||
use crate::builtins::set;
|
||||
use crate::builtins::singletons::{PyNone, PyNoneRef, PyNotImplemented, PyNotImplementedRef};
|
||||
use crate::builtins::slice::PyEllipsis;
|
||||
use crate::builtins::staticmethod::PyStaticMethod;
|
||||
use crate::builtins::tuple::{PyTuple, PyTupleRef};
|
||||
use crate::bytecode;
|
||||
use crate::exceptions::{self, PyBaseExceptionRef};
|
||||
use crate::function::{IntoFuncArgs, IntoPyNativeFunc};
|
||||
use crate::obj::objbuiltinfunc::PyFuncDef;
|
||||
use crate::obj::objbytearray;
|
||||
use crate::obj::objbytes;
|
||||
use crate::obj::objcode;
|
||||
use crate::obj::objcode::PyCodeRef;
|
||||
use crate::obj::objcomplex::PyComplex;
|
||||
use crate::obj::objdict::{PyDict, PyDictRef};
|
||||
use crate::obj::objfloat::PyFloat;
|
||||
use crate::obj::objfunction::{PyBoundMethod, PyFunction};
|
||||
use crate::obj::objgetset::{IntoPyGetterFunc, IntoPySetterFunc, PyGetSet};
|
||||
use crate::obj::objint::{PyInt, PyIntRef};
|
||||
use crate::obj::objiter;
|
||||
use crate::obj::objlist::PyList;
|
||||
use crate::obj::objnamespace::PyNamespace;
|
||||
use crate::obj::objobject;
|
||||
use crate::obj::objset;
|
||||
use crate::obj::objsingletons::{PyNone, PyNoneRef, PyNotImplemented, PyNotImplementedRef};
|
||||
use crate::obj::objslice::PyEllipsis;
|
||||
use crate::obj::objstaticmethod::PyStaticMethod;
|
||||
use crate::obj::objstr;
|
||||
use crate::obj::objtuple::{PyTuple, PyTupleRef};
|
||||
use crate::obj::objtype::{self, PyType, PyTypeRef};
|
||||
pub use crate::pyobjectrc::{PyObjectRc, PyObjectWeak};
|
||||
use crate::scope::Scope;
|
||||
use crate::slots::{PyTpFlags, PyTypeSlots};
|
||||
@@ -144,7 +144,7 @@ impl PyContext {
|
||||
);
|
||||
|
||||
let tp_new_wrapper = create_object(
|
||||
PyFuncDef::from(objtype::tp_new_wrapper.into_func()).into_function(),
|
||||
PyFuncDef::from(pytype::tp_new_wrapper.into_func()).into_function(),
|
||||
&types.builtin_function_or_method_type,
|
||||
)
|
||||
.into_object();
|
||||
@@ -216,14 +216,14 @@ impl PyContext {
|
||||
|
||||
pub fn new_str<S>(&self, s: S) -> PyObjectRef
|
||||
where
|
||||
S: Into<objstr::PyStr>,
|
||||
S: Into<pystr::PyStr>,
|
||||
{
|
||||
PyObject::new(s.into(), self.types.str_type.clone(), None)
|
||||
}
|
||||
|
||||
pub fn new_bytes(&self, data: Vec<u8>) -> PyObjectRef {
|
||||
PyObject::new(
|
||||
objbytes::PyBytes::from(data),
|
||||
bytes::PyBytes::from(data),
|
||||
self.types.bytes_type.clone(),
|
||||
None,
|
||||
)
|
||||
@@ -231,7 +231,7 @@ impl PyContext {
|
||||
|
||||
pub fn new_bytearray(&self, data: Vec<u8>) -> PyObjectRef {
|
||||
PyObject::new(
|
||||
objbytearray::PyByteArray::from(data),
|
||||
bytearray::PyByteArray::from(data),
|
||||
self.types.bytearray_type.clone(),
|
||||
None,
|
||||
)
|
||||
@@ -255,10 +255,10 @@ impl PyContext {
|
||||
PyObject::new(PyList::from(elements), self.types.list_type.clone(), None)
|
||||
}
|
||||
|
||||
pub fn new_set(&self) -> objset::PySetRef {
|
||||
pub fn new_set(&self) -> set::PySetRef {
|
||||
// Initialized empty, as calling __hash__ is required for adding each object to the set
|
||||
// which requires a VM context - this is done in the objset code itself.
|
||||
PyRef::new_ref(objset::PySet::default(), self.types.set_type.clone(), None)
|
||||
// which requires a VM context - this is done in the set code itself.
|
||||
PyRef::new_ref(set::PySet::default(), self.types.set_type.clone(), None)
|
||||
}
|
||||
|
||||
pub fn new_dict(&self) -> PyDictRef {
|
||||
@@ -284,8 +284,8 @@ impl PyContext {
|
||||
PyFuncDef::from(f.into_func()).build_function(self)
|
||||
}
|
||||
|
||||
pub(crate) fn new_stringref(&self, s: String) -> objstr::PyStrRef {
|
||||
PyRef::new_ref(objstr::PyStr::from(s), self.types.str_type.clone(), None)
|
||||
pub(crate) fn new_stringref(&self, s: String) -> pystr::PyStrRef {
|
||||
PyRef::new_ref(pystr::PyStr::from(s), self.types.str_type.clone(), None)
|
||||
}
|
||||
|
||||
pub fn new_function_named<F, FKind>(&self, f: F, name: String) -> PyFuncDef
|
||||
@@ -345,11 +345,7 @@ impl PyContext {
|
||||
}
|
||||
|
||||
pub fn new_code_object(&self, code: bytecode::CodeObject) -> PyCodeRef {
|
||||
PyRef::new_ref(
|
||||
objcode::PyCode::new(code),
|
||||
self.types.code_type.clone(),
|
||||
None,
|
||||
)
|
||||
PyRef::new_ref(code::PyCode::new(code), self.types.code_type.clone(), None)
|
||||
}
|
||||
|
||||
pub fn new_pyfunction(
|
||||
@@ -378,7 +374,7 @@ impl PyContext {
|
||||
PyObject {
|
||||
typ: PyRwLock::new(class.into_typed_pyobj()),
|
||||
dict: dict.map(|d| PyRwLock::new(d.into_typed_pyobj())),
|
||||
payload: objobject::PyBaseObject,
|
||||
payload: object::PyBaseObject,
|
||||
}
|
||||
.into_ref()
|
||||
}
|
||||
@@ -584,7 +580,7 @@ where
|
||||
T: PyValue,
|
||||
{
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
if objtype::isinstance(&obj, &T::class(vm)) {
|
||||
if pytype::isinstance(&obj, &T::class(vm)) {
|
||||
PyRef::from_obj(obj, vm)
|
||||
} else {
|
||||
let class = T::class(vm);
|
||||
@@ -833,7 +829,7 @@ impl<T> PyIterable<T> {
|
||||
let method = &self.method;
|
||||
let iter_obj = vm.invoke(method, ())?;
|
||||
|
||||
let length_hint = objiter::length_hint(vm, iter_obj.clone())?;
|
||||
let length_hint = iter::length_hint(vm, iter_obj.clone())?;
|
||||
|
||||
Ok(PyIterator {
|
||||
vm,
|
||||
@@ -861,7 +857,7 @@ where
|
||||
match self.vm.call_method(&self.obj, "__next__", ()) {
|
||||
Ok(value) => Some(T::try_from_object(self.vm, value)),
|
||||
Err(err) => {
|
||||
if objtype::isinstance(&err, &self.vm.ctx.exceptions.stop_iteration) {
|
||||
if pytype::isinstance(&err, &self.vm.ctx.exceptions.stop_iteration) {
|
||||
None
|
||||
} else {
|
||||
Some(Err(err))
|
||||
@@ -892,7 +888,7 @@ where
|
||||
})?;
|
||||
Self::try_from_object(
|
||||
vm,
|
||||
objiter::PySequenceIterator::new_forward(obj)
|
||||
iter::PySequenceIterator::new_forward(obj)
|
||||
.into_ref(vm)
|
||||
.into_object(),
|
||||
)
|
||||
@@ -1077,7 +1073,7 @@ impl PyObject<dyn PyObjectPayload> {
|
||||
&self,
|
||||
vm: &VirtualMachine,
|
||||
) -> Option<&T> {
|
||||
if objtype::issubclass(self.class(), &T::class(vm)) {
|
||||
if pytype::issubclass(self.class(), &T::class(vm)) {
|
||||
self.payload()
|
||||
} else {
|
||||
None
|
||||
@@ -1126,7 +1122,7 @@ pub trait PyValue: fmt::Debug + PyThreadingConstraint + Sized + 'static {
|
||||
|
||||
fn into_ref_with_type(self, vm: &VirtualMachine, cls: PyTypeRef) -> PyResult<PyRef<Self>> {
|
||||
let class = Self::class(vm);
|
||||
if objtype::issubclass(&cls, &class) {
|
||||
if pytype::issubclass(&cls, &class) {
|
||||
Ok(self.into_ref_with_type_unchecked(cls, vm))
|
||||
} else {
|
||||
let subtype = vm.to_str(&cls.obj)?;
|
||||
@@ -1193,7 +1189,7 @@ impl<A: IntoPyObject, B: IntoPyObject> IntoPyObject for Either<A, B> {
|
||||
///
|
||||
/// ```
|
||||
/// use rustpython_vm::VirtualMachine;
|
||||
/// use rustpython_vm::obj::{objstr::PyStrRef, objint::PyIntRef};
|
||||
/// use rustpython_vm::builtins::{PyStrRef, PyIntRef};
|
||||
/// use rustpython_vm::pyobject::Either;
|
||||
///
|
||||
/// fn do_something(arg: Either<PyIntRef, PyStrRef>, vm: &VirtualMachine) {
|
||||
@@ -1253,11 +1249,7 @@ pub trait PyClassImpl: PyClassDef {
|
||||
if Self::TP_FLAGS.has_feature(PyTpFlags::HAS_DICT) {
|
||||
class.set_str_attr(
|
||||
"__dict__",
|
||||
ctx.new_getset(
|
||||
"__dict__",
|
||||
objobject::object_get_dict,
|
||||
objobject::object_set_dict,
|
||||
),
|
||||
ctx.new_getset("__dict__", object::object_get_dict, object::object_set_dict),
|
||||
);
|
||||
}
|
||||
Self::impl_extend_class(ctx, class);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
use std::fmt;
|
||||
|
||||
use crate::obj::objdict::PyDictRef;
|
||||
use crate::builtins::dict::PyDictRef;
|
||||
use crate::pyobject::{ItemProtocol, PyContext, PyObjectRef, PyResult};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@ use num_bigint::BigInt;
|
||||
use num_traits::{One, Signed, ToPrimitive, Zero};
|
||||
use std::ops::Range;
|
||||
|
||||
use crate::obj::objint::PyInt;
|
||||
use crate::obj::objslice::{PySlice, PySliceRef};
|
||||
use crate::builtins::int::PyInt;
|
||||
use crate::builtins::slice::{PySlice, PySliceRef};
|
||||
use crate::pyobject::{BorrowValue, Either, PyObjectRef, PyResult, TryFromObject, TypeProtocol};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use crate::builtins::memory::Buffer;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::common::hash::PyHash;
|
||||
use crate::common::lock::PyRwLock;
|
||||
use crate::function::{FuncArgs, OptionalArg, PyNativeFunc};
|
||||
use crate::obj::objmemory::Buffer;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::pyobject::{
|
||||
Either, IdProtocol, PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
|
||||
};
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
use crate::builtins::bytes::PyBytesRef;
|
||||
use crate::builtins::float::try_float;
|
||||
use crate::builtins::iter;
|
||||
use crate::builtins::list::PyList;
|
||||
use crate::builtins::memory::{Buffer, BufferOptions};
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::builtins::slice::PySliceRef;
|
||||
use crate::common::borrow::{BorrowedValue, BorrowedValueMut};
|
||||
use crate::common::lock::{
|
||||
PyMappedRwLockReadGuard, PyMappedRwLockWriteGuard, PyRwLock, PyRwLockReadGuard,
|
||||
PyRwLockUpgradableReadGuard, PyRwLockWriteGuard,
|
||||
};
|
||||
use crate::function::OptionalArg;
|
||||
use crate::obj::objbytes::PyBytesRef;
|
||||
use crate::obj::objfloat::try_float;
|
||||
use crate::obj::objiter;
|
||||
use crate::obj::objlist::PyList;
|
||||
use crate::obj::objmemory::{Buffer, BufferOptions};
|
||||
use crate::obj::objslice::PySliceRef;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, IdProtocol, IntoPyObject, PyClassImpl, PyComparisonValue, PyIterable,
|
||||
PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
@@ -928,7 +928,7 @@ impl PyArrayIter {
|
||||
if let Some(item) = self.array.borrow_value().getitem_by_idx(pos, vm) {
|
||||
Ok(item)
|
||||
} else {
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ use num_complex::Complex64;
|
||||
|
||||
use rustpython_parser::{ast, mode::Mode, parser};
|
||||
|
||||
use crate::obj::objlist::PyListRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::builtins::list::PyListRef;
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::pyobject::{IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::slots::PyTpFlags;
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
@@ -2,11 +2,11 @@ pub(crate) use decl::make_module;
|
||||
|
||||
#[pymodule(name = "binascii")]
|
||||
mod decl {
|
||||
use crate::builtins::bytearray::{PyByteArray, PyByteArrayRef};
|
||||
use crate::builtins::bytes::{PyBytes, PyBytesRef};
|
||||
use crate::builtins::pystr::{PyStr, PyStrRef};
|
||||
use crate::byteslike::PyBytesLike;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::obj::objbytearray::{PyByteArray, PyByteArrayRef};
|
||||
use crate::obj::objbytes::{PyBytes, PyBytesRef};
|
||||
use crate::obj::objstr::{PyStr, PyStrRef};
|
||||
use crate::pyobject::{BorrowValue, PyObjectRef, PyResult, TryFromObject, TypeProtocol};
|
||||
use crate::vm::VirtualMachine;
|
||||
use crc::{crc32, Hasher32};
|
||||
|
||||
@@ -2,9 +2,9 @@ pub(crate) use _collections::make_module;
|
||||
|
||||
#[pymodule]
|
||||
mod _collections {
|
||||
use crate::builtins::{iter, pytype::PyTypeRef};
|
||||
use crate::common::lock::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard};
|
||||
use crate::function::OptionalArg;
|
||||
use crate::obj::{objiter, objtype::PyTypeRef};
|
||||
use crate::pyobject::{PyComparisonValue, PyIterable, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::slots::{Comparable, PyComparisonOp};
|
||||
use crate::vm::ReprGuard;
|
||||
@@ -372,7 +372,7 @@ mod _collections {
|
||||
let ret = deque[pos].clone();
|
||||
Ok(ret)
|
||||
} else {
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ use csv as rust_csv;
|
||||
use itertools::{self, Itertools};
|
||||
use std::fmt::{self, Debug, Formatter};
|
||||
|
||||
use crate::builtins::iter;
|
||||
use crate::builtins::pystr::{self, PyStr};
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::common::lock::PyRwLock;
|
||||
use crate::function::FuncArgs;
|
||||
use crate::obj::objiter;
|
||||
use crate::obj::objstr::{self, PyStr};
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IntoPyObject, PyClassImpl, PyIterable, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
TryFromObject, TypeProtocol,
|
||||
@@ -30,7 +30,7 @@ struct ReaderOption {
|
||||
impl ReaderOption {
|
||||
fn new(args: FuncArgs, vm: &VirtualMachine) -> PyResult<Self> {
|
||||
let delimiter = if let Some(delimiter) = args.get_optional_kwarg("delimiter") {
|
||||
*objstr::borrow_value(&delimiter)
|
||||
*pystr::borrow_value(&delimiter)
|
||||
.as_bytes()
|
||||
.iter()
|
||||
.exactly_one()
|
||||
@@ -43,7 +43,7 @@ impl ReaderOption {
|
||||
};
|
||||
|
||||
let quotechar = if let Some(quotechar) = args.get_optional_kwarg("quotechar") {
|
||||
*objstr::borrow_value("echar)
|
||||
*pystr::borrow_value("echar)
|
||||
.as_bytes()
|
||||
.iter()
|
||||
.exactly_one()
|
||||
@@ -178,7 +178,7 @@ impl Reader {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
}
|
||||
} else {
|
||||
unreachable!()
|
||||
|
||||
@@ -2,10 +2,10 @@ pub(crate) use decl::make_module;
|
||||
|
||||
#[pymodule(name = "dis")]
|
||||
mod decl {
|
||||
use crate::builtins::code::PyCodeRef;
|
||||
use crate::builtins::dict::PyDictRef;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::bytecode::CodeFlags;
|
||||
use crate::obj::objcode::PyCodeRef;
|
||||
use crate::obj::objdict::PyDictRef;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::pyobject::{BorrowValue, ItemProtocol, PyObjectRef, PyResult, TryFromObject};
|
||||
use crate::vm::VirtualMachine;
|
||||
use rustpython_compiler::compile;
|
||||
|
||||
@@ -2,9 +2,9 @@ pub(crate) use _functools::make_module;
|
||||
|
||||
#[pymodule]
|
||||
mod _functools {
|
||||
use crate::builtins::iter;
|
||||
use crate::builtins::pytype;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::obj::objiter;
|
||||
use crate::obj::objtype;
|
||||
use crate::pyobject::{PyObjectRef, PyResult};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
@@ -15,13 +15,13 @@ mod _functools {
|
||||
start_value: OptionalArg<PyObjectRef>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
let iterator = objiter::get_iter(vm, &sequence)?;
|
||||
let iterator = iter::get_iter(vm, &sequence)?;
|
||||
|
||||
let start_value = if let OptionalArg::Present(val) = start_value {
|
||||
val
|
||||
} else {
|
||||
objiter::call_next(vm, &iterator).map_err(|err| {
|
||||
if objtype::isinstance(&err, &vm.ctx.exceptions.stop_iteration) {
|
||||
iter::call_next(vm, &iterator).map_err(|err| {
|
||||
if pytype::isinstance(&err, &vm.ctx.exceptions.stop_iteration) {
|
||||
let exc_type = vm.ctx.exceptions.type_error.clone();
|
||||
vm.new_exception_msg(
|
||||
exc_type,
|
||||
@@ -35,7 +35,7 @@ mod _functools {
|
||||
|
||||
let mut accumulator = start_value;
|
||||
|
||||
while let Ok(next_obj) = objiter::call_next(vm, &iterator) {
|
||||
while let Ok(next_obj) = iter::call_next(vm, &iterator) {
|
||||
accumulator = vm.invoke(&function, vec![accumulator, next_obj])?
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ pub(crate) use hashlib::make_module;
|
||||
|
||||
#[pymodule]
|
||||
mod hashlib {
|
||||
use crate::builtins::bytes::{PyBytes, PyBytesRef};
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::common::lock::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard};
|
||||
use crate::function::{FuncArgs, OptionalArg};
|
||||
use crate::obj::objbytes::{PyBytes, PyBytesRef};
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{BorrowValue, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
use std::fmt;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::builtins::bytes::PyBytesRef;
|
||||
use crate::builtins::code::PyCode;
|
||||
use crate::builtins::module::PyModuleRef;
|
||||
use crate::builtins::pystr;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::import;
|
||||
use crate::obj::objbytes::PyBytesRef;
|
||||
use crate::obj::objcode::PyCode;
|
||||
use crate::obj::objmodule::PyModuleRef;
|
||||
use crate::obj::objstr;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::pyobject::{BorrowValue, ItemProtocol, PyObjectRef, PyResult};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
@@ -60,7 +60,7 @@ fn _imp_is_frozen(name: PyStrRef, vm: &VirtualMachine) -> bool {
|
||||
fn _imp_create_builtin(spec: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
let sys_modules = vm.get_attribute(vm.sys_module.clone(), "modules").unwrap();
|
||||
let spec = vm.get_attribute(spec, "name")?;
|
||||
let name = objstr::borrow_value(&spec);
|
||||
let name = pystr::borrow_value(&spec);
|
||||
|
||||
if let Ok(module) = sys_modules.get_item(name, vm) {
|
||||
Ok(module)
|
||||
|
||||
+24
-22
@@ -17,6 +17,16 @@ mod _io {
|
||||
use num_traits::ToPrimitive;
|
||||
use std::io::{self, prelude::*, Cursor, SeekFrom};
|
||||
|
||||
use crate::builtins::bytearray::PyByteArray;
|
||||
use crate::builtins::bytes::PyBytesRef;
|
||||
use crate::builtins::int;
|
||||
use crate::builtins::iter;
|
||||
use crate::builtins::memory::{
|
||||
Buffer, BufferOptions, BufferRef, PyMemoryView, PyMemoryViewRef,
|
||||
};
|
||||
use crate::builtins::pybool;
|
||||
use crate::builtins::pystr::{self, PyStr, PyStrRef};
|
||||
use crate::builtins::pytype::{self, PyTypeRef};
|
||||
use crate::byteslike::{PyBytesLike, PyRwBytesLike};
|
||||
use crate::common::borrow::{BorrowedValue, BorrowedValueMut};
|
||||
use crate::common::lock::{
|
||||
@@ -24,14 +34,6 @@ mod _io {
|
||||
};
|
||||
use crate::exceptions::{IntoPyException, PyBaseExceptionRef};
|
||||
use crate::function::{FuncArgs, OptionalArg, OptionalOption};
|
||||
use crate::obj::objbool;
|
||||
use crate::obj::objbytearray::PyByteArray;
|
||||
use crate::obj::objbytes::PyBytesRef;
|
||||
use crate::obj::objint;
|
||||
use crate::obj::objiter;
|
||||
use crate::obj::objmemory::{Buffer, BufferOptions, BufferRef, PyMemoryView, PyMemoryViewRef};
|
||||
use crate::obj::objstr::{self, PyStr, PyStrRef};
|
||||
use crate::obj::objtype::{self, PyTypeRef};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
TryFromObject,
|
||||
@@ -266,7 +268,7 @@ mod _io {
|
||||
|
||||
#[pymethod]
|
||||
fn close(instance: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
|
||||
let closed = objbool::boolval(vm, Self::closed(instance.clone(), vm)?)?;
|
||||
let closed = pybool::boolval(vm, Self::closed(instance.clone(), vm)?)?;
|
||||
if !closed {
|
||||
let res = vm.call_method(&instance, "flush", ());
|
||||
vm.set_attr(&instance, "__closed", vm.ctx.new_bool(true))?;
|
||||
@@ -308,7 +310,7 @@ mod _io {
|
||||
msg: OptionalOption<PyObjectRef>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
if objbool::boolval(vm, vm.get_attribute(instance, "closed")?)? {
|
||||
if pybool::boolval(vm, vm.get_attribute(instance, "closed")?)? {
|
||||
let msg = msg
|
||||
.flatten()
|
||||
.unwrap_or_else(|| vm.ctx.new_str("I/O operation on closed file"));
|
||||
@@ -324,7 +326,7 @@ mod _io {
|
||||
msg: OptionalOption<PyObjectRef>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
if !objbool::boolval(vm, vm.call_method(&instance, "readable", ())?)? {
|
||||
if !pybool::boolval(vm, vm.call_method(&instance, "readable", ())?)? {
|
||||
let msg = msg
|
||||
.flatten()
|
||||
.unwrap_or_else(|| vm.ctx.new_str("File or stream is not readable."));
|
||||
@@ -340,7 +342,7 @@ mod _io {
|
||||
msg: OptionalOption<PyObjectRef>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
if !objbool::boolval(vm, vm.call_method(&instance, "writable", ())?)? {
|
||||
if !pybool::boolval(vm, vm.call_method(&instance, "writable", ())?)? {
|
||||
let msg = msg
|
||||
.flatten()
|
||||
.unwrap_or_else(|| vm.ctx.new_str("File or stream is not writable."));
|
||||
@@ -356,7 +358,7 @@ mod _io {
|
||||
msg: OptionalOption<PyObjectRef>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
if !objbool::boolval(vm, vm.call_method(&instance, "seekable", ())?)? {
|
||||
if !pybool::boolval(vm, vm.call_method(&instance, "seekable", ())?)? {
|
||||
let msg = msg
|
||||
.flatten()
|
||||
.unwrap_or_else(|| vm.ctx.new_str("File or stream is not seekable."));
|
||||
@@ -373,8 +375,8 @@ mod _io {
|
||||
#[pymethod(magic)]
|
||||
fn next(instance: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
let line = vm.call_method(&instance, "readline", ())?;
|
||||
if !objbool::boolval(vm, line.clone())? {
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
if !pybool::boolval(vm, line.clone())? {
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
} else {
|
||||
Ok(line)
|
||||
}
|
||||
@@ -726,7 +728,7 @@ mod _io {
|
||||
let buffered_reader_class = vm.try_class("_io", "BufferedReader")?;
|
||||
let raw = vm.get_attribute(instance, "buffer").unwrap();
|
||||
|
||||
if !objtype::isinstance(&raw, &buffered_reader_class) {
|
||||
if !pytype::isinstance(&raw, &buffered_reader_class) {
|
||||
// TODO: this should be io.UnsupportedOperation error which derives both from ValueError *and* OSError
|
||||
return Err(vm.new_value_error("not readable".to_owned()));
|
||||
}
|
||||
@@ -750,7 +752,7 @@ mod _io {
|
||||
let buffered_writer_class = vm.try_class("_io", "BufferedWriter")?;
|
||||
let raw = vm.get_attribute(instance, "buffer").unwrap();
|
||||
|
||||
if !objtype::isinstance(&raw, &buffered_writer_class) {
|
||||
if !pytype::isinstance(&raw, &buffered_writer_class) {
|
||||
// TODO: this should be io.UnsupportedOperation error which derives from ValueError and OSError
|
||||
return Err(vm.new_value_error("not writable".to_owned()));
|
||||
}
|
||||
@@ -758,7 +760,7 @@ mod _io {
|
||||
let bytes = obj.borrow_value().to_owned().into_bytes();
|
||||
|
||||
let len = vm.call_method(&raw, "write", (vm.ctx.new_bytes(bytes.clone()),))?;
|
||||
let len = objint::try_to_primitive(objint::get_value(&len), vm)?;
|
||||
let len = int::try_to_primitive(int::get_value(&len), vm)?;
|
||||
|
||||
// returns the count of unicode code points written
|
||||
let len = from_utf8(&bytes[..len])
|
||||
@@ -777,7 +779,7 @@ mod _io {
|
||||
let buffered_reader_class = vm.try_class("_io", "BufferedReader")?;
|
||||
let raw = vm.get_attribute(instance, "buffer").unwrap();
|
||||
|
||||
if !objtype::isinstance(&raw, &buffered_reader_class) {
|
||||
if !pytype::isinstance(&raw, &buffered_reader_class) {
|
||||
// TODO: this should be io.UnsupportedOperation error which derives both from ValueError *and* OSError
|
||||
return Err(vm.new_value_error("not readable".to_owned()));
|
||||
}
|
||||
@@ -837,7 +839,7 @@ mod _io {
|
||||
) -> PyResult<StringIORef> {
|
||||
let raw_bytes = object
|
||||
.flatten()
|
||||
.map_or_else(Vec::new, |v| objstr::borrow_value(&v).as_bytes().to_vec());
|
||||
.map_or_else(Vec::new, |v| pystr::borrow_value(&v).as_bytes().to_vec());
|
||||
|
||||
StringIO {
|
||||
buffer: PyRwLock::new(BufferedIO::new(Cursor::new(raw_bytes))),
|
||||
@@ -1470,11 +1472,11 @@ mod _io {
|
||||
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
|
||||
mod fileio {
|
||||
use super::_io::*;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::byteslike::{PyBytesLike, PyRwBytesLike};
|
||||
use crate::exceptions::IntoPyException;
|
||||
use crate::function::{FuncArgs, OptionalArg};
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
|
||||
};
|
||||
|
||||
+15
-13
@@ -8,14 +8,16 @@ mod decl {
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
|
||||
use crate::builtins::int::{self, PyInt, PyIntRef};
|
||||
use crate::builtins::iter::{
|
||||
call_next, get_all, get_iter, get_next_object, new_stop_iteration,
|
||||
};
|
||||
use crate::builtins::pybool;
|
||||
use crate::builtins::pytype::{self, PyTypeRef};
|
||||
use crate::builtins::tuple::PyTupleRef;
|
||||
use crate::common::lock::{PyMutex, PyRwLock, PyRwLockWriteGuard};
|
||||
use crate::common::rc::PyRc;
|
||||
use crate::function::{Args, FuncArgs, OptionalArg, OptionalOption};
|
||||
use crate::obj::objbool;
|
||||
use crate::obj::objint::{self, PyInt, PyIntRef};
|
||||
use crate::obj::objiter::{call_next, get_all, get_iter, get_next_object, new_stop_iteration};
|
||||
use crate::obj::objtuple::PyTupleRef;
|
||||
use crate::obj::objtype::{self, PyTypeRef};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IdProtocol, IntoPyRef, PyCallable, PyObjectRc, PyObjectRef, PyObjectWeak,
|
||||
PyRef, PyResult, PyValue, TypeProtocol,
|
||||
@@ -72,7 +74,7 @@ mod decl {
|
||||
match call_next(vm, &cur_iter) {
|
||||
Ok(ok) => return Ok(ok),
|
||||
Err(err) => {
|
||||
if objtype::isinstance(&err, &vm.ctx.exceptions.stop_iteration) {
|
||||
if pytype::isinstance(&err, &vm.ctx.exceptions.stop_iteration) {
|
||||
self.cur_idx.fetch_add(1);
|
||||
*self.cached_iter.write() = None;
|
||||
} else {
|
||||
@@ -145,7 +147,7 @@ mod decl {
|
||||
fn next(&self, vm: &VirtualMachine) -> PyResult {
|
||||
loop {
|
||||
let sel_obj = call_next(vm, &self.selector)?;
|
||||
let verdict = objbool::boolval(vm, sel_obj.clone())?;
|
||||
let verdict = pybool::boolval(vm, sel_obj.clone())?;
|
||||
let data_obj = call_next(vm, &self.data)?;
|
||||
|
||||
if verdict {
|
||||
@@ -420,7 +422,7 @@ mod decl {
|
||||
let predicate = &self.predicate;
|
||||
|
||||
let verdict = vm.invoke(predicate, (obj.clone(),))?;
|
||||
let verdict = objbool::boolval(vm, verdict)?;
|
||||
let verdict = pybool::boolval(vm, verdict)?;
|
||||
if verdict {
|
||||
Ok(obj)
|
||||
} else {
|
||||
@@ -479,7 +481,7 @@ mod decl {
|
||||
let obj = call_next(vm, iterable)?;
|
||||
let pred = predicate.clone();
|
||||
let pred_value = vm.invoke(&pred.into_object(), (obj.clone(),))?;
|
||||
if !objbool::boolval(vm, pred_value)? {
|
||||
if !pybool::boolval(vm, pred_value)? {
|
||||
self.start_flag.store(true);
|
||||
return Ok(obj);
|
||||
}
|
||||
@@ -696,9 +698,9 @@ mod decl {
|
||||
}
|
||||
|
||||
fn pyobject_to_opt_usize(obj: PyObjectRef, vm: &VirtualMachine) -> Option<usize> {
|
||||
let is_int = objtype::isinstance(&obj, &vm.ctx.types.int_type);
|
||||
let is_int = pytype::isinstance(&obj, &vm.ctx.types.int_type);
|
||||
if is_int {
|
||||
objint::get_value(&obj).to_usize()
|
||||
int::get_value(&obj).to_usize()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -850,7 +852,7 @@ mod decl {
|
||||
vm.invoke(predicate, vec![obj.clone()])?
|
||||
};
|
||||
|
||||
if !objbool::boolval(vm, pred_value)? {
|
||||
if !pybool::boolval(vm, pred_value)? {
|
||||
return Ok(obj);
|
||||
}
|
||||
}
|
||||
@@ -1522,7 +1524,7 @@ mod decl {
|
||||
let next_obj = match call_next(vm, &self.iterators[idx]) {
|
||||
Ok(obj) => obj,
|
||||
Err(err) => {
|
||||
if !objtype::isinstance(&err, &vm.ctx.exceptions.stop_iteration) {
|
||||
if !pytype::isinstance(&err, &vm.ctx.exceptions.stop_iteration) {
|
||||
return Err(err);
|
||||
}
|
||||
numactive -= 1;
|
||||
|
||||
@@ -4,11 +4,11 @@ mod machinery;
|
||||
#[pymodule]
|
||||
mod _json {
|
||||
use super::*;
|
||||
use crate::builtins::iter;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::builtins::{pybool, pytype::PyTypeRef};
|
||||
use crate::exceptions::PyBaseExceptionRef;
|
||||
use crate::function::{FuncArgs, OptionalArg};
|
||||
use crate::obj::objiter;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::{objbool, objtype::PyTypeRef};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
|
||||
};
|
||||
@@ -41,7 +41,7 @@ mod _json {
|
||||
impl JsonScanner {
|
||||
#[pyslot]
|
||||
fn tp_new(cls: PyTypeRef, ctx: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
|
||||
let strict = objbool::boolval(vm, vm.get_attribute(ctx.clone(), "strict")?)?;
|
||||
let strict = pybool::boolval(vm, vm.get_attribute(ctx.clone(), "strict")?)?;
|
||||
let object_hook = vm.option_if_none(vm.get_attribute(ctx.clone(), "object_hook")?);
|
||||
let object_pairs_hook =
|
||||
vm.option_if_none(vm.get_attribute(ctx.clone(), "object_pairs_hook")?);
|
||||
@@ -83,7 +83,7 @@ mod _json {
|
||||
let c = s
|
||||
.chars()
|
||||
.next()
|
||||
.ok_or_else(|| objiter::stop_iter_with_value(vm.ctx.new_int(idx), vm))?;
|
||||
.ok_or_else(|| iter::stop_iter_with_value(vm.ctx.new_int(idx), vm))?;
|
||||
let next_idx = idx + c.len_utf8();
|
||||
match c {
|
||||
'"' => {
|
||||
@@ -151,7 +151,7 @@ mod _json {
|
||||
parse_constant!("Infinity");
|
||||
parse_constant!("-Infinity");
|
||||
|
||||
Err(objiter::stop_iter_with_value(vm.ctx.new_int(idx), vm))
|
||||
Err(iter::stop_iter_with_value(vm.ctx.new_int(idx), vm))
|
||||
}
|
||||
|
||||
fn parse_number(&self, s: &str, vm: &VirtualMachine) -> Option<(PyResult, usize)> {
|
||||
@@ -199,7 +199,7 @@ mod _json {
|
||||
if idx > 0 {
|
||||
chars
|
||||
.nth(idx - 1)
|
||||
.ok_or_else(|| objiter::stop_iter_with_value(vm.ctx.new_int(idx), vm))?;
|
||||
.ok_or_else(|| iter::stop_iter_with_value(vm.ctx.new_int(idx), vm))?;
|
||||
}
|
||||
zelf.parse(
|
||||
chars.as_str(),
|
||||
|
||||
@@ -5,7 +5,7 @@ pub(crate) use decl::make_module;
|
||||
mod decl {
|
||||
use rustpython_parser::lexer;
|
||||
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::pyobject::{BorrowValue, PyObjectRef, PyResult};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ pub(crate) use decl::make_module;
|
||||
|
||||
#[pymodule(name = "marshal")]
|
||||
mod decl {
|
||||
use crate::builtins::bytes::PyBytes;
|
||||
use crate::builtins::code::{PyCode, PyCodeRef};
|
||||
use crate::bytecode;
|
||||
use crate::byteslike::PyBytesLike;
|
||||
use crate::common::borrow::BorrowValue;
|
||||
use crate::obj::objbytes::PyBytes;
|
||||
use crate::obj::objcode::{PyCode, PyCodeRef};
|
||||
use crate::pyobject::{PyObjectRef, PyResult, TryFromObject};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
|
||||
+11
-11
@@ -9,10 +9,10 @@ use statrs::function::gamma::{gamma, ln_gamma};
|
||||
use num_bigint::BigInt;
|
||||
use num_traits::{One, Signed, Zero};
|
||||
|
||||
use crate::builtins::float::{self, IntoPyFloat, PyFloatRef};
|
||||
use crate::builtins::int::{self, PyInt, PyIntRef};
|
||||
use crate::builtins::pytype;
|
||||
use crate::function::{Args, OptionalArg};
|
||||
use crate::obj::objfloat::{self, IntoPyFloat, PyFloatRef};
|
||||
use crate::obj::objint::{self, PyInt, PyIntRef};
|
||||
use crate::obj::objtype;
|
||||
use crate::pyobject::{BorrowValue, Either, PyObjectRef, PyResult, TypeProtocol};
|
||||
use crate::vm::VirtualMachine;
|
||||
use rustpython_common::float_ops;
|
||||
@@ -265,9 +265,9 @@ fn math_trunc(value: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
/// * `value` - Either a float or a python object which implements __ceil__
|
||||
/// * `vm` - Represents the python state.
|
||||
fn math_ceil(value: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
if objtype::isinstance(&value, &vm.ctx.types.float_type) {
|
||||
let v = objfloat::get_value(&value);
|
||||
let v = objfloat::try_bigint(v.ceil(), vm)?;
|
||||
if pytype::isinstance(&value, &vm.ctx.types.float_type) {
|
||||
let v = float::get_value(&value);
|
||||
let v = float::try_bigint(v.ceil(), vm)?;
|
||||
Ok(vm.ctx.new_int(v))
|
||||
} else {
|
||||
try_magic_method("__ceil__", vm, &value)
|
||||
@@ -281,9 +281,9 @@ fn math_ceil(value: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
/// * `value` - Either a float or a python object which implements __ceil__
|
||||
/// * `vm` - Represents the python state.
|
||||
fn math_floor(value: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
if objtype::isinstance(&value, &vm.ctx.types.float_type) {
|
||||
let v = objfloat::get_value(&value);
|
||||
let v = objfloat::try_bigint(v.floor(), vm)?;
|
||||
if pytype::isinstance(&value, &vm.ctx.types.float_type) {
|
||||
let v = float::get_value(&value);
|
||||
let v = float::try_bigint(v.floor(), vm)?;
|
||||
Ok(vm.ctx.new_int(v))
|
||||
} else {
|
||||
try_magic_method("__floor__", vm, &value)
|
||||
@@ -307,9 +307,9 @@ fn math_ldexp(
|
||||
) -> PyResult<f64> {
|
||||
let value = match value {
|
||||
Either::A(f) => f.to_f64(),
|
||||
Either::B(z) => objint::try_float(z.borrow_value(), vm)?,
|
||||
Either::B(z) => int::try_float(z.borrow_value(), vm)?,
|
||||
};
|
||||
Ok(value * (2_f64).powf(objint::try_float(i.borrow_value(), vm)?))
|
||||
Ok(value * (2_f64).powf(int::try_float(i.borrow_value(), vm)?))
|
||||
}
|
||||
|
||||
fn math_perf_arb_len_int_op<F>(args: Args<PyIntRef>, op: F, default: BigInt) -> BigInt
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::os::errno_err;
|
||||
use crate::obj::objbytes::PyBytesRef;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::builtins::bytes::PyBytesRef;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::pyobject::{BorrowValue, PyObjectRef, PyResult};
|
||||
use crate::VirtualMachine;
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::builtins::{iter, pytype};
|
||||
use crate::byteslike::PyBytesLike;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::{objiter, objtype};
|
||||
use crate::pyobject::{BorrowValue, Either, PyObjectRef, PyResult, TypeProtocol};
|
||||
use crate::VirtualMachine;
|
||||
use volatile::Volatile;
|
||||
|
||||
fn _operator_length_hint(obj: PyObjectRef, default: OptionalArg, vm: &VirtualMachine) -> PyResult {
|
||||
let default = default.unwrap_or_else(|| vm.ctx.new_int(0));
|
||||
if !objtype::isinstance(&default, &vm.ctx.types.int_type) {
|
||||
if !pytype::isinstance(&default, &vm.ctx.types.int_type) {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"'{}' type cannot be interpreted as an integer",
|
||||
default.class().name
|
||||
)));
|
||||
}
|
||||
let hint = objiter::length_hint(vm, obj)?
|
||||
let hint = iter::length_hint(vm, obj)?
|
||||
.map(|i| vm.ctx.new_int(i))
|
||||
.unwrap_or(default);
|
||||
Ok(hint)
|
||||
|
||||
+13
-13
@@ -10,18 +10,18 @@ use crossbeam_utils::atomic::AtomicCell;
|
||||
use num_traits::ToPrimitive;
|
||||
|
||||
use super::errno::errors;
|
||||
use crate::builtins::bytes::{PyBytes, PyBytesRef};
|
||||
use crate::builtins::dict::PyDictRef;
|
||||
use crate::builtins::int::{PyInt, PyIntRef};
|
||||
use crate::builtins::iter;
|
||||
use crate::builtins::pystr::{PyStr, PyStrRef};
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::builtins::set::PySet;
|
||||
use crate::builtins::tuple::PyTupleRef;
|
||||
use crate::byteslike::PyBytesLike;
|
||||
use crate::common::lock::PyRwLock;
|
||||
use crate::exceptions::{IntoPyException, PyBaseExceptionRef};
|
||||
use crate::function::{FuncArgs, IntoPyNativeFunc, OptionalArg};
|
||||
use crate::obj::objbytes::{PyBytes, PyBytesRef};
|
||||
use crate::obj::objdict::PyDictRef;
|
||||
use crate::obj::objint::{PyInt, PyIntRef};
|
||||
use crate::obj::objiter;
|
||||
use crate::obj::objset::PySet;
|
||||
use crate::obj::objstr::{PyStr, PyStrRef};
|
||||
use crate::obj::objtuple::PyTupleRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, IntoPyObject, ItemProtocol, PyObjectRef, PyRef, PyResult,
|
||||
PyStructSequence, PyValue, TryFromObject, TypeProtocol,
|
||||
@@ -560,7 +560,7 @@ mod _os {
|
||||
#[pymethod(name = "__next__")]
|
||||
fn next(&self, vm: &VirtualMachine) -> PyResult {
|
||||
if self.exhausted.load() {
|
||||
return Err(objiter::new_stop_iteration(vm));
|
||||
return Err(iter::new_stop_iteration(vm));
|
||||
}
|
||||
|
||||
match self.entries.write().next() {
|
||||
@@ -575,7 +575,7 @@ mod _os {
|
||||
},
|
||||
None => {
|
||||
self.exhausted.store(true);
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -981,8 +981,8 @@ fn to_seconds_from_unix_epoch(sys_time: SystemTime) -> f64 {
|
||||
mod posix {
|
||||
use super::*;
|
||||
|
||||
use crate::obj::objdict::PyMapping;
|
||||
use crate::obj::objlist::PyListRef;
|
||||
use crate::builtins::dict::PyMapping;
|
||||
use crate::builtins::list::PyListRef;
|
||||
use crate::pyobject::PyIterable;
|
||||
use bitflags::bitflags;
|
||||
use nix::errno::Errno;
|
||||
@@ -2202,7 +2202,7 @@ pub(crate) use posix::raw_set_inheritable;
|
||||
#[pymodule]
|
||||
mod nt {
|
||||
use super::*;
|
||||
use crate::obj::objlist::PyListRef;
|
||||
use crate::builtins::list::PyListRef;
|
||||
pub(super) use std::os::windows::fs::OpenOptionsExt;
|
||||
use std::os::windows::io::RawHandle;
|
||||
#[cfg(target_env = "msvc")]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::builtins::int::PyIntRef;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::exceptions::IntoPyException;
|
||||
use crate::obj::objint::PyIntRef;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::pyobject::{BorrowValue, PyClassImpl, PyObjectRef, PyResult, PyStructSequence};
|
||||
use crate::vm::VirtualMachine;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
@@ -22,13 +22,13 @@ pub(crate) mod _struct {
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::iter::Peekable;
|
||||
|
||||
use crate::builtins::{
|
||||
bytes::PyBytesRef, iter, pybool::IntoPyBool, pystr::PyStr, pystr::PyStrRef,
|
||||
pytype::PyTypeRef, tuple::PyTupleRef,
|
||||
};
|
||||
use crate::byteslike::{PyBytesLike, PyRwBytesLike};
|
||||
use crate::exceptions::PyBaseExceptionRef;
|
||||
use crate::function::Args;
|
||||
use crate::obj::{
|
||||
objbool::IntoPyBool, objbytes::PyBytesRef, objiter, objstr::PyStr, objstr::PyStrRef,
|
||||
objtuple::PyTupleRef, objtype::PyTypeRef,
|
||||
};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
|
||||
};
|
||||
@@ -853,7 +853,7 @@ pub(crate) mod _struct {
|
||||
let size = self.format_spec.size();
|
||||
let offset = self.offset.fetch_add(size);
|
||||
if offset + size > self.buffer.len() {
|
||||
Err(objiter::new_stop_iteration(vm))
|
||||
Err(iter::new_stop_iteration(vm))
|
||||
} else {
|
||||
self.buffer
|
||||
.with_ref(|buf| self.format_spec.unpack(&buf[offset..offset + size], vm))
|
||||
|
||||
@@ -4,10 +4,10 @@ pub(crate) use _random::make_module;
|
||||
|
||||
#[pymodule]
|
||||
mod _random {
|
||||
use crate::builtins::int::PyIntRef;
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::common::lock::PyMutex;
|
||||
use crate::function::OptionalOption;
|
||||
use crate::obj::objint::PyIntRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{BorrowValue, PyRef, PyResult, PyValue};
|
||||
use crate::VirtualMachine;
|
||||
use num_bigint::{BigInt, Sign};
|
||||
|
||||
+3
-3
@@ -9,10 +9,10 @@ use regex::bytes::{Captures, Regex, RegexBuilder};
|
||||
use std::fmt;
|
||||
use std::ops::Range;
|
||||
|
||||
use crate::builtins::int::{PyInt, PyIntRef};
|
||||
use crate::builtins::pystr::{PyStr, PyStrRef};
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::function::{Args, OptionalArg};
|
||||
use crate::obj::objint::{PyInt, PyIntRef};
|
||||
use crate::obj::objstr::{PyStr, PyStrRef};
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, IntoPyObject, PyClassImpl, PyObjectRef, PyResult, PyValue, TryFromObject,
|
||||
};
|
||||
|
||||
@@ -2,9 +2,9 @@ pub(crate) use _serde_json::make_module;
|
||||
|
||||
#[pymodule]
|
||||
mod _serde_json {
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::common::borrow::BorrowValue;
|
||||
use crate::exceptions::PyBaseExceptionRef;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::py_serde;
|
||||
use crate::pyobject::{PyResult, TryFromObject};
|
||||
use crate::VirtualMachine;
|
||||
|
||||
@@ -10,14 +10,14 @@ use gethostname::gethostname;
|
||||
use nix::unistd::sethostname;
|
||||
use socket2::{Domain, Protocol, Socket, Type as SocketType};
|
||||
|
||||
use crate::builtins::bytearray::PyByteArrayRef;
|
||||
use crate::builtins::bytes::PyBytesRef;
|
||||
use crate::builtins::pystr::{PyStr, PyStrRef};
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::builtins::tuple::PyTupleRef;
|
||||
use crate::byteslike::PyBytesLike;
|
||||
use crate::exceptions::{IntoPyException, PyBaseExceptionRef};
|
||||
use crate::function::{FuncArgs, OptionalArg};
|
||||
use crate::obj::objbytearray::PyByteArrayRef;
|
||||
use crate::obj::objbytes::PyBytesRef;
|
||||
use crate::obj::objstr::{PyStr, PyStrRef};
|
||||
use crate::obj::objtuple::PyTupleRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, IntoPyObject, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
TryFromObject,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use super::socket::PySocketRef;
|
||||
use crate::builtins::bytearray::PyByteArrayRef;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::builtins::{pytype::PyTypeRef, weakref::PyWeak};
|
||||
use crate::byteslike::PyBytesLike;
|
||||
use crate::common::lock::{PyRwLock, PyRwLockWriteGuard};
|
||||
use crate::exceptions::{IntoPyException, PyBaseExceptionRef};
|
||||
use crate::function::OptionalArg;
|
||||
use crate::obj::objbytearray::PyByteArrayRef;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::{objtype::PyTypeRef, objweakref::PyWeak};
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, IntoPyObject, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult,
|
||||
PyValue,
|
||||
@@ -113,7 +113,7 @@ fn obj2py(obj: &Asn1ObjectRef) -> PyNid {
|
||||
|
||||
#[cfg(windows)]
|
||||
fn ssl_enum_certificates(store_name: PyStrRef, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
|
||||
use crate::obj::objset::PyFrozenSet;
|
||||
use crate::builtins::set::PyFrozenSet;
|
||||
use schannel::{cert_context::ValidUses, cert_store::CertStore, RawPointer};
|
||||
use winapi::um::wincrypt;
|
||||
// TODO: check every store for it, not just 2 of them:
|
||||
|
||||
@@ -7,12 +7,12 @@ pub(crate) use _string::make_module;
|
||||
mod _string {
|
||||
use std::mem;
|
||||
|
||||
use crate::builtins::list::PyList;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::exceptions::IntoPyException;
|
||||
use crate::format::{
|
||||
FieldName, FieldNamePart, FieldType, FormatPart, FormatString, FromTemplate,
|
||||
};
|
||||
use crate::obj::objlist::PyList;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::pyobject::{BorrowValue, IntoPyObject, PyObjectRef, PyResult};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ pub(crate) use decl::make_module;
|
||||
mod decl {
|
||||
use std::fmt;
|
||||
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::pyobject::{BorrowValue, PyRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
use rustpython_compiler::{compile, error::CompileError, symboltable};
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::builtins::dict::PyDictRef;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::builtins::tuple::PyTupleRef;
|
||||
/// Implementation of the _thread module
|
||||
use crate::exceptions::{self, IntoPyException};
|
||||
use crate::function::{FuncArgs, OptionalArg};
|
||||
use crate::obj::objdict::PyDictRef;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::objtuple::PyTupleRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, IdProtocol, ItemProtocol, PyCallable, PyClassImpl, PyObjectRef, PyRef,
|
||||
PyResult, PyValue, TypeProtocol,
|
||||
|
||||
@@ -7,10 +7,10 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use chrono::naive::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||
use chrono::{Datelike, Timelike};
|
||||
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::builtins::tuple::PyTupleRef;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::objtuple::PyTupleRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{
|
||||
BorrowValue, Either, PyClassImpl, PyObjectRef, PyResult, PyStructSequence, TryFromObject,
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ pub(crate) use decl::make_module;
|
||||
mod decl {
|
||||
use std::iter::FromIterator;
|
||||
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::pyobject::{BorrowValue, PyResult};
|
||||
use crate::vm::VirtualMachine;
|
||||
use rustpython_parser::lexer;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
See also: https://docs.python.org/3/library/unicodedata.html
|
||||
*/
|
||||
|
||||
use crate::builtins::pystr::PyStrRef;
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::obj::objstr::PyStrRef;
|
||||
use crate::obj::objtype::PyTypeRef;
|
||||
use crate::pyobject::{BorrowValue, PyClassImpl, PyObject, PyObjectRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
|
||||
Loaded 100 of 112 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user