mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Add missing with(Iterable)
This commit is contained in:
1 parent
2abf21b134
commit
9b9dd1100a
26 files changed
+80
-70
No files matched your search
+1
-1
@@ -1405,7 +1405,7 @@ mod array {
|
||||
internal: PyMutex<PositionIterInternal<PyArrayRef>>,
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext), flags(HAS_DICT))]
|
||||
#[pyclass(with(IterNext, Iterable), flags(HAS_DICT))]
|
||||
impl PyArrayIter {
|
||||
#[pymethod(magic)]
|
||||
fn setstate(&self, state: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ mod _csv {
|
||||
function::{ArgIterable, ArgumentError, FromArgs, FuncArgs},
|
||||
match_class,
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
types::{IterNext, IterNextIterable},
|
||||
types::{IterNext, IterNextIterable, Iterable},
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use itertools::{self, Itertools};
|
||||
@@ -166,7 +166,7 @@ mod _csv {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext))]
|
||||
#[pyclass(with(IterNext, Iterable))]
|
||||
impl Reader {}
|
||||
impl IterNextIterable for Reader {}
|
||||
impl IterNext for Reader {
|
||||
|
||||
@@ -15,7 +15,7 @@ pub(crate) mod _struct {
|
||||
function::{ArgBytesLike, ArgMemoryBuffer, PosArgs},
|
||||
match_class,
|
||||
protocol::PyIterReturn,
|
||||
types::{Constructor, IterNext, IterNextIterable},
|
||||
types::{Constructor, IterNext, IterNextIterable, Iterable},
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
@@ -194,7 +194,7 @@ pub(crate) mod _struct {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext))]
|
||||
#[pyclass(with(IterNext, Iterable))]
|
||||
impl UnpackIterator {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> usize {
|
||||
|
||||
@@ -1377,7 +1377,7 @@ mod _sqlite {
|
||||
statement: Option<PyRef<Statement>>,
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext), flags(BASETYPE))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable), flags(BASETYPE))]
|
||||
impl Cursor {
|
||||
fn new(
|
||||
connection: PyRef<Connection>,
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{
|
||||
frame::FrameRef,
|
||||
function::OptionalArg,
|
||||
protocol::PyIterReturn,
|
||||
types::{Constructor, IterNext, IterNextIterable, Representable, Unconstructible},
|
||||
types::{Constructor, IterNext, IterNextIterable, Iterable, Representable, Unconstructible},
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
@@ -195,7 +195,7 @@ impl PyPayload for PyAsyncGenASend {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext))]
|
||||
#[pyclass(with(IterNext, Iterable))]
|
||||
impl PyAsyncGenASend {
|
||||
#[pymethod(name = "__await__")]
|
||||
fn r#await(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
|
||||
@@ -290,7 +290,7 @@ impl PyPayload for PyAsyncGenAThrow {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext))]
|
||||
#[pyclass(with(IterNext, Iterable))]
|
||||
impl PyAsyncGenAThrow {
|
||||
#[pymethod(name = "__await__")]
|
||||
fn r#await(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
|
||||
|
||||
@@ -891,7 +891,7 @@ impl PyPayload for PyByteArrayIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl PyByteArrayIterator {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> usize {
|
||||
|
||||
@@ -688,7 +688,7 @@ impl PyPayload for PyBytesIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl PyBytesIterator {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> usize {
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
frame::FrameRef,
|
||||
function::OptionalArg,
|
||||
protocol::PyIterReturn,
|
||||
types::{Constructor, IterNext, IterNextIterable, Representable, Unconstructible},
|
||||
types::{Constructor, IterNext, IterNextIterable, Iterable, Representable, Unconstructible},
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
@@ -128,7 +128,7 @@ impl PyPayload for PyCoroutineWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext))]
|
||||
#[pyclass(with(IterNext, Iterable))]
|
||||
impl PyCoroutineWrapper {
|
||||
#[pymethod]
|
||||
fn send(&self, val: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
|
||||
|
||||
@@ -839,7 +839,7 @@ macro_rules! dict_view {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl $iter_name {
|
||||
fn new(dict: PyDictRef) -> Self {
|
||||
$iter_name {
|
||||
@@ -912,7 +912,7 @@ macro_rules! dict_view {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl $reverse_iter_name {
|
||||
fn new(dict: PyDictRef) -> Self {
|
||||
let size = dict.size();
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
convert::ToPyObject,
|
||||
function::OptionalArg,
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
types::{Constructor, IterNext, IterNextIterable},
|
||||
types::{Constructor, IterNext, IterNextIterable, Iterable},
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use num_bigint::BigInt;
|
||||
@@ -52,7 +52,7 @@ impl Constructor for PyEnumerate {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Py, IterNext, Constructor), flags(BASETYPE))]
|
||||
#[pyclass(with(Py, IterNext, Iterable, Constructor), flags(BASETYPE))]
|
||||
impl PyEnumerate {
|
||||
#[pyclassmethod(magic)]
|
||||
fn class_getitem(cls: PyTypeRef, args: PyObjectRef, vm: &VirtualMachine) -> PyGenericAlias {
|
||||
@@ -97,7 +97,7 @@ impl PyPayload for PyReverseSequenceIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext))]
|
||||
#[pyclass(with(IterNext, Iterable))]
|
||||
impl PyReverseSequenceIterator {
|
||||
pub fn new(obj: PyObjectRef, len: usize) -> Self {
|
||||
let position = len.saturating_sub(1);
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::{PyType, PyTypeRef};
|
||||
use crate::{
|
||||
class::PyClassImpl,
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
types::{Constructor, IterNext, IterNextIterable},
|
||||
types::{Constructor, IterNext, IterNextIterable, Iterable},
|
||||
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ impl Constructor for PyFilter {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor), flags(BASETYPE))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor), flags(BASETYPE))]
|
||||
impl PyFilter {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(&self, vm: &VirtualMachine) -> (PyTypeRef, (PyObjectRef, PyIter)) {
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::{
|
||||
frame::FrameRef,
|
||||
function::OptionalArg,
|
||||
protocol::PyIterReturn,
|
||||
types::{Constructor, IterNext, IterNextIterable, Representable, Unconstructible},
|
||||
types::{Constructor, IterNext, IterNextIterable, Iterable, Representable, Unconstructible},
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ impl PyPayload for PyGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Py, Constructor, IterNext))]
|
||||
#[pyclass(with(Py, Constructor, IterNext, Iterable))]
|
||||
impl PyGenerator {
|
||||
pub fn as_coro(&self) -> &Coro {
|
||||
&self.inner
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
function::ArgCallable,
|
||||
object::{Traverse, TraverseFn},
|
||||
protocol::{PyIterReturn, PySequence, PySequenceMethods},
|
||||
types::{IterNext, IterNextIterable},
|
||||
types::{IterNext, IterNextIterable, Iterable},
|
||||
Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use rustpython_common::{
|
||||
@@ -189,7 +189,7 @@ impl PyPayload for PySequenceIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext))]
|
||||
#[pyclass(with(IterNext, Iterable))]
|
||||
impl PySequenceIterator {
|
||||
pub fn new(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<Self> {
|
||||
let seq = PySequence::try_protocol(&obj, vm)?;
|
||||
@@ -252,7 +252,7 @@ impl PyPayload for PyCallableIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext))]
|
||||
#[pyclass(with(IterNext, Iterable))]
|
||||
impl PyCallableIterator {
|
||||
pub fn new(callable: ArgCallable, sentinel: PyObjectRef) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -543,7 +543,7 @@ impl PyPayload for PyListIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl PyListIterator {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> usize {
|
||||
@@ -588,7 +588,7 @@ impl PyPayload for PyListReverseIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl PyListReverseIterator {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> usize {
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::{
|
||||
class::PyClassImpl,
|
||||
function::PosArgs,
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
types::{Constructor, IterNext, IterNextIterable},
|
||||
types::{Constructor, IterNext, IterNextIterable, Iterable},
|
||||
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ impl Constructor for PyMap {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor), flags(BASETYPE))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor), flags(BASETYPE))]
|
||||
impl PyMap {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self, vm: &VirtualMachine) -> PyResult<usize> {
|
||||
|
||||
@@ -1137,7 +1137,7 @@ impl PyPayload for PyMemoryViewIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl PyMemoryViewIterator {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(&self, vm: &VirtualMachine) -> PyTupleRef {
|
||||
|
||||
@@ -537,7 +537,7 @@ impl PyPayload for PyLongRangeIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl PyLongRangeIterator {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> BigInt {
|
||||
@@ -602,7 +602,7 @@ impl PyPayload for PyRangeIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl PyRangeIterator {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> usize {
|
||||
|
||||
@@ -1232,7 +1232,7 @@ impl PyPayload for PySetIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl PySetIterator {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> usize {
|
||||
|
||||
@@ -206,7 +206,7 @@ impl PyPayload for PyStrIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl PyStrIterator {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> usize {
|
||||
|
||||
@@ -434,7 +434,7 @@ impl PyPayload for PyTupleIterator {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, IterNext))]
|
||||
#[pyclass(with(Constructor, IterNext, Iterable))]
|
||||
impl PyTupleIterator {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> usize {
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::{
|
||||
class::PyClassImpl,
|
||||
function::{ArgIntoBool, OptionalArg, PosArgs},
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
types::{Constructor, IterNext, IterNextIterable},
|
||||
types::{Constructor, IterNext, IterNextIterable, Iterable},
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use rustpython_common::atomic::{self, PyAtomic, Radium};
|
||||
@@ -41,7 +41,7 @@ impl Constructor for PyZip {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor), flags(BASETYPE))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor), flags(BASETYPE))]
|
||||
impl PyZip {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyTupleRef> {
|
||||
|
||||
@@ -623,7 +623,7 @@ mod _collections {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor))]
|
||||
impl PyDequeIterator {
|
||||
pub(crate) fn new(deque: PyDequeRef) -> Self {
|
||||
PyDequeIterator {
|
||||
@@ -696,7 +696,7 @@ mod _collections {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor))]
|
||||
impl PyReverseDequeIterator {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> usize {
|
||||
|
||||
+1
-1
@@ -382,7 +382,7 @@ mod _io {
|
||||
#[derive(Debug, PyPayload)]
|
||||
pub struct _IOBase;
|
||||
|
||||
#[pyclass(with(IterNext, Destructor), flags(BASETYPE, HAS_DICT))]
|
||||
#[pyclass(with(IterNext, Iterable, Destructor), flags(BASETYPE, HAS_DICT))]
|
||||
impl _IOBase {
|
||||
#[pymethod]
|
||||
fn seek(
|
||||
|
||||
+24
-24
@@ -16,7 +16,7 @@ mod decl {
|
||||
identifier,
|
||||
protocol::{PyIter, PyIterReturn, PyNumber},
|
||||
stdlib::sys,
|
||||
types::{Constructor, IterNext, IterNextIterable, Representable},
|
||||
types::{Constructor, IterNext, IterNextIterable, Iterable, Representable},
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, PyWeakRef, TryFromObject,
|
||||
VirtualMachine,
|
||||
};
|
||||
@@ -32,7 +32,7 @@ mod decl {
|
||||
active: PyRwLock<Option<PyIter>>,
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext), flags(BASETYPE, HAS_DICT))]
|
||||
#[pyclass(with(IterNext, Iterable), flags(BASETYPE, HAS_DICT))]
|
||||
impl PyItertoolsChain {
|
||||
#[pyslot]
|
||||
fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
@@ -189,7 +189,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor), flags(BASETYPE))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor), flags(BASETYPE))]
|
||||
impl PyItertoolsCompress {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<Self>) -> (PyTypeRef, (PyIter, PyIter)) {
|
||||
@@ -249,7 +249,7 @@ mod decl {
|
||||
return Err(vm.new_type_error("a number is required".to_owned()));
|
||||
}
|
||||
|
||||
PyItertoolsCount {
|
||||
Self {
|
||||
cur: PyRwLock::new(start),
|
||||
step,
|
||||
}
|
||||
@@ -258,7 +258,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor, Representable))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor, Representable))]
|
||||
impl PyItertoolsCount {
|
||||
// TODO: Implement this
|
||||
// if (lz->cnt == PY_SSIZE_T_MAX)
|
||||
@@ -314,7 +314,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor), flags(BASETYPE))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor), flags(BASETYPE))]
|
||||
impl PyItertoolsCycle {}
|
||||
impl IterNextIterable for PyItertoolsCycle {}
|
||||
impl IterNext for PyItertoolsCycle {
|
||||
@@ -378,7 +378,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor, Representable), flags(BASETYPE))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor, Representable), flags(BASETYPE))]
|
||||
impl PyItertoolsRepeat {
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self, vm: &VirtualMachine) -> PyResult<usize> {
|
||||
@@ -456,7 +456,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor), flags(BASETYPE))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor), flags(BASETYPE))]
|
||||
impl PyItertoolsStarmap {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<Self>) -> (PyTypeRef, (PyObjectRef, PyIter)) {
|
||||
@@ -519,7 +519,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor), flags(BASETYPE))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor), flags(BASETYPE))]
|
||||
impl PyItertoolsTakewhile {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<Self>) -> (PyTypeRef, (PyObjectRef, PyIter), u32) {
|
||||
@@ -600,7 +600,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor), flags(BASETYPE))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor), flags(BASETYPE))]
|
||||
impl PyItertoolsDropwhile {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<Self>) -> (PyTypeRef, (PyObjectRef, PyIter), u32) {
|
||||
@@ -719,7 +719,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor))]
|
||||
impl PyItertoolsGroupBy {
|
||||
pub(super) fn advance(
|
||||
&self,
|
||||
@@ -795,7 +795,7 @@ mod decl {
|
||||
groupby: PyRef<PyItertoolsGroupBy>,
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext))]
|
||||
#[pyclass(with(IterNext, Iterable))]
|
||||
impl PyItertoolsGrouper {}
|
||||
impl IterNextIterable for PyItertoolsGrouper {}
|
||||
impl IterNext for PyItertoolsGrouper {
|
||||
@@ -865,7 +865,7 @@ mod decl {
|
||||
)))
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext), flags(BASETYPE))]
|
||||
#[pyclass(with(IterNext, Iterable), flags(BASETYPE))]
|
||||
impl PyItertoolsIslice {
|
||||
#[pyslot]
|
||||
fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
@@ -1023,7 +1023,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor), flags(BASETYPE))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor), flags(BASETYPE))]
|
||||
impl PyItertoolsFilterFalse {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<Self>) -> (PyTypeRef, (PyObjectRef, PyIter)) {
|
||||
@@ -1091,7 +1091,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor))]
|
||||
impl PyItertoolsAccumulate {}
|
||||
|
||||
impl IterNextIterable for PyItertoolsAccumulate {}
|
||||
@@ -1199,7 +1199,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor))]
|
||||
impl PyItertoolsTee {
|
||||
fn from_iter(iterator: PyIter, vm: &VirtualMachine) -> PyResult {
|
||||
let class = PyItertoolsTee::class(&vm.ctx);
|
||||
@@ -1277,7 +1277,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor))]
|
||||
impl PyItertoolsProduct {
|
||||
fn update_idxs(&self, mut idxs: PyRwLockWriteGuard<'_, Vec<usize>>) {
|
||||
if idxs.len() == 0 {
|
||||
@@ -1370,7 +1370,7 @@ mod decl {
|
||||
|
||||
let n = pool.len();
|
||||
|
||||
PyItertoolsCombinations {
|
||||
Self {
|
||||
pool,
|
||||
indices: PyRwLock::new((0..r).collect()),
|
||||
result: PyRwLock::new(None),
|
||||
@@ -1382,7 +1382,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor))]
|
||||
impl PyItertoolsCombinations {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyTupleRef {
|
||||
@@ -1512,7 +1512,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor))]
|
||||
impl PyItertoolsCombinationsWithReplacement {}
|
||||
|
||||
impl IterNextIterable for PyItertoolsCombinationsWithReplacement {}
|
||||
@@ -1609,7 +1609,7 @@ mod decl {
|
||||
None => n,
|
||||
};
|
||||
|
||||
PyItertoolsPermutations {
|
||||
Self {
|
||||
pool,
|
||||
indices: PyRwLock::new((0..n).collect()),
|
||||
cycles: PyRwLock::new((0..r.min(n)).map(|i| n - i).collect()),
|
||||
@@ -1622,7 +1622,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor))]
|
||||
impl PyItertoolsPermutations {}
|
||||
impl IterNextIterable for PyItertoolsPermutations {}
|
||||
impl IterNext for PyItertoolsPermutations {
|
||||
@@ -1725,7 +1725,7 @@ mod decl {
|
||||
fillvalue: PyRwLock<PyObjectRef>,
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor))]
|
||||
impl PyItertoolsZipLongest {
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyTupleRef> {
|
||||
@@ -1794,7 +1794,7 @@ mod decl {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
#[pyclass(with(IterNext, Iterable, Constructor))]
|
||||
impl PyItertoolsPairwise {}
|
||||
impl IterNextIterable for PyItertoolsPairwise {}
|
||||
impl IterNext for PyItertoolsPairwise {
|
||||
|
||||
+2
-2
@@ -316,7 +316,7 @@ pub(super) mod _os {
|
||||
function::{ArgBytesLike, Either, FsPath, FuncArgs, OptionalArg},
|
||||
protocol::PyIterReturn,
|
||||
recursion::ReprGuard,
|
||||
types::{IterNext, IterNextIterable, PyStructSequence, Representable},
|
||||
types::{IterNext, IterNextIterable, Iterable, PyStructSequence, Representable},
|
||||
vm::VirtualMachine,
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
|
||||
};
|
||||
@@ -791,7 +791,7 @@ pub(super) mod _os {
|
||||
mode: OutputMode,
|
||||
}
|
||||
|
||||
#[pyclass(with(IterNext))]
|
||||
#[pyclass(with(IterNext, Iterable))]
|
||||
impl ScandirIterator {
|
||||
#[pymethod]
|
||||
fn close(&self) {
|
||||
|
||||
+14
-4
@@ -305,6 +305,7 @@ fn iter_wrapper(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
vm.call_special_method(&zelf, identifier!(vm, __iter__), ())
|
||||
}
|
||||
|
||||
// PyObject_IterNextIterable in CPython
|
||||
fn self_iter(zelf: PyObjectRef, _vm: &VirtualMachine) -> PyResult {
|
||||
Ok(zelf)
|
||||
}
|
||||
@@ -1233,7 +1234,6 @@ pub trait AsNumber: PyPayload {
|
||||
#[pyclass]
|
||||
pub trait Iterable: PyPayload {
|
||||
#[pyslot]
|
||||
#[pymethod(name = "__iter__")]
|
||||
fn slot_iter(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
let zelf = zelf
|
||||
.downcast()
|
||||
@@ -1241,6 +1241,11 @@ pub trait Iterable: PyPayload {
|
||||
Self::iter(zelf, vm)
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
fn __iter__(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
Self::slot_iter(zelf, vm)
|
||||
}
|
||||
|
||||
fn iter(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult;
|
||||
|
||||
fn extend_slots(_slots: &mut PyTypeSlots) {}
|
||||
@@ -1273,8 +1278,13 @@ where
|
||||
T: IterNextIterable,
|
||||
{
|
||||
#[cold]
|
||||
fn slot_iter(_zelf: PyObjectRef, _vm: &VirtualMachine) -> PyResult {
|
||||
unreachable!("slot is overriden");
|
||||
fn slot_iter(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
let repr = zelf.repr(vm)?;
|
||||
unreachable!("slot must be overriden for {}", repr.as_str());
|
||||
}
|
||||
|
||||
fn __iter__(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
self_iter(zelf, vm)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
@@ -1284,6 +1294,6 @@ where
|
||||
|
||||
fn extend_slots(slots: &mut PyTypeSlots) {
|
||||
let prev = slots.iter.swap(Some(self_iter));
|
||||
debug_assert!(prev.is_some()); // slot_iter would be set
|
||||
debug_assert!(prev.is_some()); // slot_iter would be set
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user