Skip to content

Conversation

@mpajkowski
Copy link
Contributor

Hello,

I added iteration support for str.

Copy link
Member

@coolreader18 coolreader18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thank you for contributing to the project! I've made a comment on your changes and the CI is failing due to a linting error, but fix that up and this is good to merge.

#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyStringIterator {
PyStringIterator {
position: Cell::new(0),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you're missing the __reversed__ method somewhere here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I checked it using CPython (3.7.3):

>>> hasattr(str, "__reversed__")
False

Should I implement __reversed__ despite this fact or leave it unchanged?

Copy link
Member

@coolreader18 coolreader18 Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is PyStringReverseIterator used then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within reverse:

string = "123456789"
reversed_iter = reversed(string)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but nowhere in your code do you construct a PyStringReverseIterator, so there's no way to actually get one in Python code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! I'll fix it in a moment.

@mpajkowski
Copy link
Contributor Author

Thanks for your feedback :) I'll deliver corrections today.

PySliceableSequence trait methods require Range<usize>
as arguments
@mpajkowski
Copy link
Contributor Author

I corrected lint warning and added __reverse__ method - it seems to be an easiest solution.

@coolreader18 coolreader18 merged commit a91470d into RustPython:master Jul 24, 2019
@mpajkowski mpajkowski deleted the iter_str branch July 24, 2019 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants