Render typed iterators (e.g. Iterator[int]) in docstrings #2244
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes pybind11 generate much more informative typed iterators.
Strictly speaking its a potential breaking change but seems like no existing code is affected, see below.
This PR makes
py::make_iterator
andpy::make_key_iterator
returnpy::detail::iterator_state
instance instead ofpy::iterator
.It doesn't affect regular use of those functions (immediate return from
__iter__
lambda),but requires changes in user code with implicit assignments/conversions, e.g.:
Search for code that would break:
To justify intuition about low frequency of "not-immediate-return" make_iterator usage I've turned to github search API for py::make_iterator. Search is limited to 1000 files, so can't tell only for first 1000 found files (~5726 in total [web search]).
In 1000 files there are 229 unique strings with return
py:make_iterator
.The only non-comment occurrence of
py::make_iterator
without preceding return was found in (pybind?) test code here. This should also be no problem since cast should happen automatically.py::make_map_iterator
search find only two unique strings with preceding return in another 1000 files (did a separate search). No other usages. Looks like this function is much less popular.While strictly speaking a breaking change was introduced it seems like it breaks no existing code.
If you think this argument is not applicable and change to
py::make_iterator
should go to major pybind release (e.g. 3.0).compare.cpp