Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PySet is not iterable #715

Closed
samuelcolvin opened this issue Jan 7, 2020 · 2 comments · Fixed by #716
Closed

PySet is not iterable #715

samuelcolvin opened this issue Jan 7, 2020 · 2 comments · Fixed by #716

Comments

@samuelcolvin
Copy link
Contributor

As per the docs (and reproduced with pyo3 v0.8.5, python 3.7, ubuntu) PySet is not an iterator.

Therefore for element in my_set { throws an error.

I tried wrapping the set in PyList::new but got the trait std::iter::ExactSizeIterator is not implemented for &pyo3::types::PySet.

Is there a good reason to prevent iteration over sets? If not could it be added, also is there a workaround for now?

@davidhewitt
Copy link
Member

It seems to me that it is reasonable for PySet to implement this. (Have opened a PR.)

For now you can use for element in my_set.iter()? { thanks to the ObjectProtocol trait.

@samuelcolvin
Copy link
Contributor Author

samuelcolvin commented Jan 8, 2020

PySet.iter isn't documented as it is on PyList.

But thank you.

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 a pull request may close this issue.

2 participants