Uh oh!
There was an error while loading. Please reload this page.
Render typed iterators (e.g. Iterator[int]) in docstrings - #2244
Render typed iterators (e.g. Iterator[int]) in docstrings#2244sizmailov wants to merge 1 commit into
Conversation
This commit introduces minor breaking change: `make_iterator` and `make_key_iterator` now return `iterator_state` instance instead of `py::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.: py::iterator it = make_iterator(...); # requires explicit py::cast()
1701f0c to
9531c6fComparewjakob
commented
Jun 10, 2020
I'm against merging this -- first, because of the incompatibility, and because it adds a bunch of code for what is a relative niche feature. This is generally a dangerous rabbit hole: we could increase the complexity of pybind11 to generate near-perfect type annotations, but I don't think that is in the interest of the majority of the users of this project. My goal post is: do an okay job in a minimal fashion. |
wjakob
commented
Jun 10, 2020
(Side note: sorry for rejecting it after you've clearly put quite a bit of work into the PR and explanations above). |
sizmailov
commented
Jun 10, 2020
That's sad. Would it make a difference if this PR won't be breaking? |
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_iteratorandpy::make_key_iteratorreturnpy::detail::iterator_stateinstance 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_iteratorwithout preceding return was found in (pybind?) test code here. This should also be no problem since cast should happen automatically.py::make_map_iteratorsearch 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_iteratorshould go to major pybind release (e.g. 3.0).compare.cpp