mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
split Arg{Callble,Iterable} from pyobject.rs
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use rustpython_vm::builtins::{PyDictRef, PyStrRef};
|
||||
use rustpython_vm::VirtualMachine;
|
||||
use rustpython_vm::{ArgIterable, PyResult, TryFromObject};
|
||||
use rustpython_vm::{function::ArgIterable, PyResult, TryFromObject};
|
||||
|
||||
pub struct ShellHelper<'vm> {
|
||||
vm: &'vm VirtualMachine,
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::builtins::int::PyIntRef;
|
||||
use crate::cformat::CFormatString;
|
||||
use crate::function::{single_or_tuple_any, OptionalOption};
|
||||
use crate::vm::VirtualMachine;
|
||||
use crate::{PyIterator, PyObjectRef, PyResult, TryFromObject, TypeProtocol};
|
||||
use crate::{function::PyIterator, PyObjectRef, PyResult, TryFromObject, TypeProtocol};
|
||||
use num_traits::{cast::ToPrimitive, sign::Signed};
|
||||
use std::str::FromStr;
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ use crate::slots::{
|
||||
use crate::utils::Either;
|
||||
use crate::vm::VirtualMachine;
|
||||
use crate::{
|
||||
ArgIterable, IdProtocol, IntoPyObject, PyClassDef, PyClassImpl, PyComparisonValue, PyContext,
|
||||
PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
function::ArgIterable, IdProtocol, IntoPyObject, PyClassDef, PyClassImpl, PyComparisonValue,
|
||||
PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
};
|
||||
use bstr::ByteSlice;
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
|
||||
@@ -18,8 +18,8 @@ use crate::slots::{
|
||||
use crate::utils::Either;
|
||||
use crate::vm::VirtualMachine;
|
||||
use crate::{
|
||||
ArgIterable, IdProtocol, IntoPyObject, IntoPyResult, PyClassImpl, PyComparisonValue, PyContext,
|
||||
PyObjectRef, PyRef, PyResult, PyValue, TryFromBorrowedObject, TypeProtocol,
|
||||
function::ArgIterable, IdProtocol, IntoPyObject, IntoPyResult, PyClassImpl, PyComparisonValue,
|
||||
PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromBorrowedObject, TypeProtocol,
|
||||
};
|
||||
use bstr::ByteSlice;
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
|
||||
@@ -13,9 +13,9 @@ use crate::iterator;
|
||||
use crate::slots::{Comparable, Hashable, Iterable, PyComparisonOp, PyIter, Unhashable};
|
||||
use crate::vm::{ReprGuard, VirtualMachine};
|
||||
use crate::{
|
||||
ArgIterable, IdProtocol, IntoPyObject, ItemProtocol, PyArithmaticValue::*, PyAttributes,
|
||||
PyClassDef, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
TryFromObject, TypeProtocol,
|
||||
function::ArgIterable, IdProtocol, IntoPyObject, ItemProtocol, PyArithmaticValue::*,
|
||||
PyAttributes, PyClassDef, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef,
|
||||
PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
};
|
||||
|
||||
pub type DictContentType = dictdatatype::Dict;
|
||||
|
||||
@@ -9,8 +9,8 @@ use super::{int, PyInt};
|
||||
use crate::slots::PyIter;
|
||||
use crate::vm::VirtualMachine;
|
||||
use crate::{
|
||||
ArgCallable, ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
TypeProtocol,
|
||||
function::ArgCallable, ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult,
|
||||
PyValue, TypeProtocol,
|
||||
};
|
||||
|
||||
/// Marks status of iterator.
|
||||
|
||||
@@ -24,8 +24,8 @@ use crate::slots::{Comparable, Hashable, Iterable, PyComparisonOp, PyIter, Unhas
|
||||
use crate::utils::Either;
|
||||
use crate::vm::{ReprGuard, VirtualMachine};
|
||||
use crate::{
|
||||
ArgIterable, PyClassDef, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef,
|
||||
PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
function::ArgIterable, PyClassDef, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef,
|
||||
PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
};
|
||||
|
||||
/// Built-in mutable sequence.
|
||||
|
||||
@@ -32,11 +32,11 @@ mod decl {
|
||||
use crate::slots::PyComparisonOp;
|
||||
use crate::utils::Either;
|
||||
use crate::vm::VirtualMachine;
|
||||
use crate::{py_io, sysmodule};
|
||||
use crate::{
|
||||
ArgCallable, ArgIterable, IdProtocol, ItemProtocol, PyArithmaticValue, PyClassImpl,
|
||||
PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
function::ArgCallable, function::ArgIterable, IdProtocol, ItemProtocol, PyArithmaticValue,
|
||||
PyClassImpl, PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
};
|
||||
use crate::{py_io, sysmodule};
|
||||
use num_traits::{Signed, Zero};
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::slots::{Comparable, Hashable, Iterable, PyComparisonOp, PyIter, SlotC
|
||||
use crate::utils::Either;
|
||||
use crate::VirtualMachine;
|
||||
use crate::{
|
||||
ArgIterable, IdProtocol, IntoPyObject, ItemProtocol, PyClassDef, PyClassImpl,
|
||||
function::ArgIterable, IdProtocol, IntoPyObject, ItemProtocol, PyClassDef, PyClassImpl,
|
||||
PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryIntoRef, TypeProtocol,
|
||||
};
|
||||
use bstr::ByteSlice;
|
||||
|
||||
@@ -12,8 +12,8 @@ use crate::slots::{
|
||||
};
|
||||
use crate::vm::{ReprGuard, VirtualMachine};
|
||||
use crate::{
|
||||
ArgIterable, IdProtocol, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef,
|
||||
PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
function::ArgIterable, IdProtocol, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef,
|
||||
PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use std::fmt;
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::slots::PyComparisonOp;
|
||||
use crate::utils::Either;
|
||||
use crate::vm::VirtualMachine;
|
||||
use crate::{
|
||||
ArgIterable, IdProtocol, PyComparisonValue, PyObjectRef, PyResult, PyValue,
|
||||
function::ArgIterable, IdProtocol, PyComparisonValue, PyObjectRef, PyResult, PyValue,
|
||||
TryFromBorrowedObject,
|
||||
};
|
||||
use bstr::ByteSlice;
|
||||
|
||||
@@ -11,8 +11,8 @@ use crate::types::create_type_with_slots;
|
||||
use crate::StaticType;
|
||||
use crate::VirtualMachine;
|
||||
use crate::{
|
||||
ArgIterable, IdProtocol, IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult,
|
||||
PyValue, TryFromObject, TypeProtocol,
|
||||
function::ArgIterable, IdProtocol, IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef,
|
||||
PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
};
|
||||
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
mod argument;
|
||||
|
||||
use self::OptionalArg::*;
|
||||
use crate::builtins::pytype::PyTypeRef;
|
||||
use crate::builtins::tuple::PyTupleRef;
|
||||
@@ -13,6 +15,8 @@ use result_like::impl_option_like;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
pub use argument::{ArgCallable, ArgIterable, PyIterator};
|
||||
|
||||
pub trait IntoFuncArgs: Sized {
|
||||
fn into_args(self, vm: &VirtualMachine) -> FuncArgs;
|
||||
fn into_method_args(self, obj: PyObjectRef, vm: &VirtualMachine) -> FuncArgs {
|
||||
|
||||
113
vm/src/function/argument.rs
Normal file
113
vm/src/function/argument.rs
Normal file
@@ -0,0 +1,113 @@
|
||||
use super::IntoFuncArgs;
|
||||
use crate::builtins::iter::PySequenceIterator;
|
||||
use crate::{
|
||||
iterator, PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ArgCallable {
|
||||
obj: PyObjectRef,
|
||||
}
|
||||
|
||||
impl ArgCallable {
|
||||
#[inline]
|
||||
pub fn invoke(&self, args: impl IntoFuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
vm.invoke(&self.obj, args)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_object(self) -> PyObjectRef {
|
||||
self.obj
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFromObject for ArgCallable {
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
if vm.is_callable(&obj) {
|
||||
Ok(ArgCallable { obj })
|
||||
} else {
|
||||
Err(vm.new_type_error(format!("'{}' object is not callable", obj.class().name())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterable Python object.
|
||||
///
|
||||
/// `ArgIterable` implements `FromArgs` so that a built-in function can accept
|
||||
/// an object that is required to conform to the Python iterator protocol.
|
||||
///
|
||||
/// ArgIterable can optionally perform type checking and conversions on iterated
|
||||
/// objects using a generic type parameter that implements `TryFromObject`.
|
||||
pub struct ArgIterable<T = PyObjectRef> {
|
||||
iterable: PyObjectRef,
|
||||
iterfn: Option<crate::slots::IterFunc>,
|
||||
_item: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> ArgIterable<T> {
|
||||
/// Returns an iterator over this sequence of objects.
|
||||
///
|
||||
/// This operation may fail if an exception is raised while invoking the
|
||||
/// `__iter__` method of the iterable object.
|
||||
pub fn iter<'a>(&self, vm: &'a VirtualMachine) -> PyResult<PyIterator<'a, T>> {
|
||||
let iter_obj = match self.iterfn {
|
||||
Some(f) => f(self.iterable.clone(), vm)?,
|
||||
None => PySequenceIterator::new(self.iterable.clone()).into_object(vm),
|
||||
};
|
||||
|
||||
let length_hint = iterator::length_hint(vm, iter_obj.clone())?;
|
||||
|
||||
Ok(PyIterator {
|
||||
vm,
|
||||
obj: iter_obj,
|
||||
length_hint,
|
||||
_item: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> TryFromObject for ArgIterable<T>
|
||||
where
|
||||
T: TryFromObject,
|
||||
{
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
let iterfn;
|
||||
{
|
||||
let cls = obj.class();
|
||||
iterfn = cls.mro_find_map(|x| x.slots.iter.load());
|
||||
if iterfn.is_none() && !cls.has_attr("__getitem__") {
|
||||
return Err(vm.new_type_error(format!("'{}' object is not iterable", cls.name())));
|
||||
}
|
||||
}
|
||||
Ok(ArgIterable {
|
||||
iterable: obj,
|
||||
iterfn,
|
||||
_item: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PyIterator<'a, T> {
|
||||
vm: &'a VirtualMachine,
|
||||
obj: PyObjectRef,
|
||||
length_hint: Option<usize>,
|
||||
_item: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<'a, T> Iterator for PyIterator<'a, T>
|
||||
where
|
||||
T: TryFromObject,
|
||||
{
|
||||
type Item = PyResult<T>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
iterator::get_next_object(self.vm, &self.obj)
|
||||
.transpose()
|
||||
.map(|x| x.and_then(|obj| T::try_from_object(self.vm, obj)))
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(self.length_hint.unwrap_or(0), self.length_hint)
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ use num_traits::ToPrimitive;
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Deref;
|
||||
|
||||
use crate::builtins::builtinfunc::PyNativeFuncDef;
|
||||
@@ -18,7 +17,6 @@ use crate::builtins::float::PyFloat;
|
||||
use crate::builtins::function::PyBoundMethod;
|
||||
use crate::builtins::getset::{IntoPyGetterFunc, IntoPySetterFunc, PyGetSet};
|
||||
use crate::builtins::int::{PyInt, PyIntRef};
|
||||
use crate::builtins::iter::PySequenceIterator;
|
||||
use crate::builtins::list::PyList;
|
||||
use crate::builtins::namespace::PyNamespace;
|
||||
use crate::builtins::object;
|
||||
@@ -35,7 +33,6 @@ use crate::common::static_cell;
|
||||
use crate::dictdatatype::Dict;
|
||||
use crate::exceptions::{self, PyBaseExceptionRef};
|
||||
use crate::function::{IntoFuncArgs, IntoPyNativeFunc};
|
||||
use crate::iterator;
|
||||
pub use crate::pyobjectrc::{PyObject, PyObjectRef, PyObjectWeak, PyRef, PyWeakRef};
|
||||
use crate::slots::{PyTpFlags, PyTypeSlots};
|
||||
use crate::types::{create_type_with_slots, TypeZoo};
|
||||
@@ -533,33 +530,6 @@ impl<T: PyValue> TryIntoRef<T> for PyRefExact<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ArgCallable {
|
||||
obj: PyObjectRef,
|
||||
}
|
||||
|
||||
impl ArgCallable {
|
||||
#[inline]
|
||||
pub fn invoke(&self, args: impl IntoFuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
vm.invoke(&self.obj, args)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_object(self) -> PyObjectRef {
|
||||
self.obj
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFromObject for ArgCallable {
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
if vm.is_callable(&obj) {
|
||||
Ok(ArgCallable { obj })
|
||||
} else {
|
||||
Err(vm.new_type_error(format!("'{}' object is not callable", obj.class().name())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait IdProtocol {
|
||||
fn get_id(&self) -> usize;
|
||||
fn is<T>(&self, other: &T) -> bool
|
||||
@@ -725,86 +695,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterable Python object.
|
||||
///
|
||||
/// `ArgIterable` implements `FromArgs` so that a built-in function can accept
|
||||
/// an object that is required to conform to the Python iterator protocol.
|
||||
///
|
||||
/// ArgIterable can optionally perform type checking and conversions on iterated
|
||||
/// objects using a generic type parameter that implements `TryFromObject`.
|
||||
pub struct ArgIterable<T = PyObjectRef> {
|
||||
iterable: PyObjectRef,
|
||||
iterfn: Option<crate::slots::IterFunc>,
|
||||
_item: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> ArgIterable<T> {
|
||||
/// Returns an iterator over this sequence of objects.
|
||||
///
|
||||
/// This operation may fail if an exception is raised while invoking the
|
||||
/// `__iter__` method of the iterable object.
|
||||
pub fn iter<'a>(&self, vm: &'a VirtualMachine) -> PyResult<PyIterator<'a, T>> {
|
||||
let iter_obj = match self.iterfn {
|
||||
Some(f) => f(self.iterable.clone(), vm)?,
|
||||
None => PySequenceIterator::new(self.iterable.clone()).into_object(vm),
|
||||
};
|
||||
|
||||
let length_hint = iterator::length_hint(vm, iter_obj.clone())?;
|
||||
|
||||
Ok(PyIterator {
|
||||
vm,
|
||||
obj: iter_obj,
|
||||
length_hint,
|
||||
_item: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> TryFromObject for ArgIterable<T>
|
||||
where
|
||||
T: TryFromObject,
|
||||
{
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
let iterfn;
|
||||
{
|
||||
let cls = obj.class();
|
||||
iterfn = cls.mro_find_map(|x| x.slots.iter.load());
|
||||
if iterfn.is_none() && !cls.has_attr("__getitem__") {
|
||||
return Err(vm.new_type_error(format!("'{}' object is not iterable", cls.name())));
|
||||
}
|
||||
}
|
||||
Ok(ArgIterable {
|
||||
iterable: obj,
|
||||
iterfn,
|
||||
_item: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PyIterator<'a, T> {
|
||||
vm: &'a VirtualMachine,
|
||||
obj: PyObjectRef,
|
||||
length_hint: Option<usize>,
|
||||
_item: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<'a, T> Iterator for PyIterator<'a, T>
|
||||
where
|
||||
T: TryFromObject,
|
||||
{
|
||||
type Item = PyResult<T>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
iterator::get_next_object(self.vm, &self.obj)
|
||||
.transpose()
|
||||
.map(|x| x.and_then(|obj| T::try_from_object(self.vm, obj)))
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(self.length_hint.unwrap_or(0), self.length_hint)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFromObject for PyObjectRef {
|
||||
#[inline]
|
||||
fn try_from_object(_vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
@@ -919,13 +809,6 @@ impl<T: PyObjectPayload> IntoPyObject for PyRef<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoPyObject for ArgCallable {
|
||||
#[inline]
|
||||
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.into_object()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoPyObject for PyObjectRef {
|
||||
#[inline]
|
||||
fn into_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
|
||||
|
||||
@@ -17,11 +17,11 @@ mod array {
|
||||
PyStr, PyStrRef, PyTypeRef,
|
||||
},
|
||||
byteslike::ArgBytesLike,
|
||||
function::OptionalArg,
|
||||
function::{ArgIterable, OptionalArg},
|
||||
sliceable::{saturate_index, PySliceableSequence, PySliceableSequenceMut, SequenceIndex},
|
||||
slots::{AsBuffer, Comparable, Iterable, PyComparisonOp, PyIter, SlotConstructor},
|
||||
ArgIterable, IdProtocol, IntoPyObject, IntoPyResult, PyComparisonValue, PyObjectRef, PyRef,
|
||||
PyResult, PyValue, StaticType, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
IdProtocol, IntoPyObject, IntoPyResult, PyComparisonValue, PyObjectRef, PyRef, PyResult,
|
||||
PyValue, StaticType, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use itertools::Itertools;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use crate::common::lock::PyMutex;
|
||||
use crate::{
|
||||
builtins::{PyStr, PyStrRef, PyTypeRef},
|
||||
function::{ArgumentError, FromArgs, FuncArgs},
|
||||
function::{ArgIterable, ArgumentError, FromArgs, FuncArgs},
|
||||
iterator,
|
||||
slots::PyIter,
|
||||
types::create_simple_type,
|
||||
ArgIterable, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject,
|
||||
TypeProtocol, VirtualMachine,
|
||||
PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject, TypeProtocol,
|
||||
VirtualMachine,
|
||||
};
|
||||
use itertools::{self, Itertools};
|
||||
use std::fmt;
|
||||
|
||||
@@ -95,8 +95,8 @@ mod _io {
|
||||
use crate::utils::Either;
|
||||
use crate::vm::{ReprGuard, VirtualMachine};
|
||||
use crate::{
|
||||
ArgIterable, IdProtocol, IntoPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
StaticType, TryFromObject, TypeProtocol,
|
||||
function::ArgIterable, IdProtocol, IntoPyObject, PyContext, PyObjectRef, PyRef, PyResult,
|
||||
PyValue, StaticType, TryFromObject, TypeProtocol,
|
||||
};
|
||||
|
||||
#[allow(clippy::let_and_return)]
|
||||
|
||||
@@ -8,11 +8,11 @@ mod decl {
|
||||
};
|
||||
use crate::{
|
||||
builtins::{int, PyInt, PyIntRef, PyTupleRef, PyTypeRef},
|
||||
function::{Args, FuncArgs, OptionalArg, OptionalOption},
|
||||
function::{ArgCallable, Args, FuncArgs, OptionalArg, OptionalOption},
|
||||
iterator::{call_next, get_iter, get_next_object},
|
||||
slots::{PyIter, SlotConstructor},
|
||||
ArgCallable, IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, PyWeakRef,
|
||||
StaticType, TypeProtocol, VirtualMachine,
|
||||
IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, PyWeakRef, StaticType,
|
||||
TypeProtocol, VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use num_bigint::BigInt;
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
use crate::{
|
||||
builtins::{try_bigint_to_f64, try_f64_to_bigint, IntoPyFloat, PyFloatRef, PyInt, PyIntRef},
|
||||
function::{Args, OptionalArg},
|
||||
function::{ArgIterable, Args, OptionalArg},
|
||||
utils::Either,
|
||||
ArgIterable, PyObjectRef, PyResult, PySequence, TypeProtocol, VirtualMachine,
|
||||
PyObjectRef, PyResult, PySequence, TypeProtocol, VirtualMachine,
|
||||
};
|
||||
use num_bigint::BigInt;
|
||||
use num_traits::{One, Signed, Zero};
|
||||
|
||||
@@ -2931,7 +2931,10 @@ mod posix {
|
||||
// cfg from nix
|
||||
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))]
|
||||
#[pyfunction]
|
||||
fn setgroups(group_ids: crate::ArgIterable<u32>, vm: &VirtualMachine) -> PyResult<()> {
|
||||
fn setgroups(
|
||||
group_ids: crate::function::ArgIterable<u32>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
let gids = group_ids
|
||||
.iter(vm)?
|
||||
.map(|entry| match entry {
|
||||
@@ -2978,13 +2981,13 @@ mod posix {
|
||||
#[pyarg(positional)]
|
||||
path: PyPathLike,
|
||||
#[pyarg(positional)]
|
||||
args: crate::ArgIterable<PyPathLike>,
|
||||
args: crate::function::ArgIterable<PyPathLike>,
|
||||
#[pyarg(positional)]
|
||||
env: crate::builtins::dict::PyMapping,
|
||||
#[pyarg(named, default)]
|
||||
file_actions: Option<crate::ArgIterable<PyTupleRef>>,
|
||||
file_actions: Option<crate::function::ArgIterable<PyTupleRef>>,
|
||||
#[pyarg(named, default)]
|
||||
setsigdef: Option<crate::ArgIterable<i32>>,
|
||||
setsigdef: Option<crate::function::ArgIterable<i32>>,
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
|
||||
|
||||
@@ -9,10 +9,10 @@ mod _sre {
|
||||
PyTypeRef,
|
||||
},
|
||||
common::hash::PyHash,
|
||||
function::{Args, OptionalArg},
|
||||
function::{ArgCallable, Args, OptionalArg},
|
||||
slots::{Comparable, Hashable},
|
||||
ArgCallable, IntoPyObject, ItemProtocol, PyComparisonValue, PyObjectRef, PyRef, PyResult,
|
||||
PyValue, StaticType, TryFromBorrowedObject, TryFromObject, VirtualMachine,
|
||||
IntoPyObject, ItemProtocol, PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
StaticType, TryFromBorrowedObject, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use core::str;
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
|
||||
@@ -4,12 +4,12 @@ use crate::{
|
||||
builtins::{pytype, weakref::PyWeak, PyStrRef, PyTypeRef},
|
||||
byteslike::{ArgBytesLike, ArgMemoryBuffer, ArgStrOrBytesLike},
|
||||
exceptions::{create_exception_type, IntoPyException, PyBaseExceptionRef},
|
||||
function::OptionalArg,
|
||||
function::{ArgCallable, OptionalArg},
|
||||
slots::SlotConstructor,
|
||||
stdlib::os::PyPathLike,
|
||||
utils::{Either, ToCString},
|
||||
ArgCallable, IntoPyObject, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
StaticType, VirtualMachine,
|
||||
IntoPyObject, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType,
|
||||
VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use foreign_types_shared::{ForeignType, ForeignTypeRef};
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
use crate::{
|
||||
builtins::{PyDictRef, PyStrRef, PyTupleRef, PyTypeRef},
|
||||
exceptions::{self, IntoPyException},
|
||||
function::{FuncArgs, KwArgs, OptionalArg},
|
||||
function::{ArgCallable, FuncArgs, KwArgs, OptionalArg},
|
||||
py_io,
|
||||
slots::{SlotGetattro, SlotSetattro},
|
||||
utils::Either,
|
||||
ArgCallable, IdProtocol, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
StaticType, TypeProtocol, VirtualMachine,
|
||||
IdProtocol, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType,
|
||||
TypeProtocol, VirtualMachine,
|
||||
};
|
||||
use parking_lot::{
|
||||
lock_api::{RawMutex as RawMutexT, RawMutexTimed, RawReentrantMutex},
|
||||
|
||||
@@ -8,7 +8,8 @@ use rustpython_vm::function::OptionalArg;
|
||||
use rustpython_vm::import::import_file;
|
||||
use rustpython_vm::VirtualMachine;
|
||||
use rustpython_vm::{
|
||||
ArgCallable, IntoPyObject, PyClassImpl, PyObject, PyObjectRef, PyResult, PyValue, StaticType,
|
||||
function::ArgCallable, IntoPyObject, PyClassImpl, PyObject, PyObjectRef, PyResult, PyValue,
|
||||
StaticType,
|
||||
};
|
||||
|
||||
use crate::{convert, js_module::PyPromise, vm_class::weak_vm, wasm_builtins::window};
|
||||
|
||||
@@ -13,8 +13,8 @@ use rustpython_vm::slots::PyIter;
|
||||
use rustpython_vm::types::create_simple_type;
|
||||
use rustpython_vm::VirtualMachine;
|
||||
use rustpython_vm::{
|
||||
ArgCallable, IntoPyObject, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, StaticType,
|
||||
TryFromObject,
|
||||
function::ArgCallable, IntoPyObject, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
StaticType, TryFromObject,
|
||||
};
|
||||
|
||||
#[wasm_bindgen(inline_js = "
|
||||
@@ -499,9 +499,16 @@ impl PyPromise {
|
||||
|
||||
Ok(PyPromise::from_future(ret_future))
|
||||
}
|
||||
PromiseKind::PyProm { then } => {
|
||||
Self::cast_result(vm.invoke(then, (on_fulfill, on_reject)), vm)
|
||||
}
|
||||
PromiseKind::PyProm { then } => Self::cast_result(
|
||||
vm.invoke(
|
||||
then,
|
||||
(
|
||||
on_fulfill.map(|c| c.into_object()),
|
||||
on_reject.map(|c| c.into_object()),
|
||||
),
|
||||
),
|
||||
vm,
|
||||
),
|
||||
PromiseKind::PyResolved(res) => match on_fulfill {
|
||||
Some(resolve) => Self::cast_result(resolve.invoke((res.clone(),), vm), vm),
|
||||
None => Ok(self.clone()),
|
||||
|
||||
Reference in New Issue
Block a user