Implement missing methods for str iterator#2906
Conversation
|
Unfortunately, both |
@DimitrisJim Uh... then, I think this revision could solve some incompatibility with cpython 3.8. PyStrIteratorRustPython(mater)>>>>> a = iter('hello')
>>>>> operator.length_hint(a)
0
>>>>> a.__setstate__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str_iterator' object has no attribute '__setstate__'
>>>>> a.__reduce__()
(<function _reconstructor at 0x55e7c6094470>, (<class 'str_iterator'>, <class 'object'>, None))CPython>>> a = iter('hello')
>>> operator.length_hint(a)
5
>>> a.__setstate__
<built-in method __setstate__ of str_iterator object at 0x7fd2441f53a0>
>>> a.__reduce__()
(<built-in function iter>, ('hello',), 0)PyStrReverseIteratorRustPython(mater)>>>>> a = reversed('hello')
>>>>> operator.length_hint(a)
0
>>>>> a.__reduce__()
(<function _reconstructor at 0x55e7c6094470>, (<class 'reversed'>, <class 'object'>, None))
>>>>> a.__setstate__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str_reverseiterator' object has no attribute '__setstate__'CPython>>> a = reversed('hello')
>>> operator.length_hint(a)
5
>>> a.__reduce__()
(<class 'reversed'>, ('hello',), 4)
>>> a.__setstate__
<built-in method __setstate__ of reversed object at 0x7fd2441f53a0>PyTupleReverseIteratorRustPython(mater)>>>>> a = reversed(tuple('hello'))
>>>>> operator.length_hint(a)
5
>>>>> a.__setstate__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'reversed' object has no attribute '__setstate__'
>>>>> a.__reduce__()
(<function _reconstructor at 0x55e7c6094470>, (<class 'reversed'>, <class 'object'>, None))CPython>>> a = reversed(tuple('hello'))
>>> operator.length_hint(a)
5
>>> a.__setstate__
<built-in method __setstate__ of reversed object at 0x7fd2441ca610>
>>> a.__reduce__()
(<class 'reversed'>, (('h', 'e', 'l', 'l', 'o'),), 4) |
|
Oh yes, code for the For the other two, separate types aren't needed. The methods you added can be placed in |
|
Oh. Thank you. I'll send v2 code about it before tomorrow. |
|
You could keep the changes for |
66ec92c to
11e5e7a
Compare
|
Ok. I dropped two commits without |
This commit implements missing methods(`__length_hint__`, `__setstate__`, `__reduce__`) in `PyStrIterator` and `PyStrReverseIterator` which cpython 3.8 provided. For implementing these methods, I add `status: AtomicCell<IterStatus>`. Implementation referenced on list.rs Signed-off-by: snowapril <sinjihng@gmail.com>
11e5e7a to
93df314
Compare
| use std::{char, ffi, fmt}; | ||
|
|
||
| use crossbeam_utils::atomic::AtomicCell; | ||
|
|
There was a problem hiding this comment.
I removed that useless blank line! Thanks for reviewing :)
Signed-off-by: snowapril <sinjihng@gmail.com>
str iterator
This revision implements the missing
PyTuplereverse iterator and methods forPyStrIteratorandPyReverseIteratorPyTupleReverseIterator
PyStrIterator
PyStrReverseIterator
These changes solve some part of
TestReversed.test_lenin test_enumerate.py.I also look into some cpython codes for fixing the rest of failed test in
test_len, current implementation ofiterator::length_hintneed to be replaced bysequence protocol.Therefore I add trivial comments about it.