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

Is it possible to type the iterator? #76

Closed
alkatar21 opened this issue Jan 15, 2022 · 1 comment
Closed

Is it possible to type the iterator? #76

alkatar21 opened this issue Jan 15, 2022 · 1 comment

Comments

@alkatar21
Copy link

This is probably more of a question and I don't know where else to ask it right now.

Is it possible to type the iterator?

I don't know if pybind11 doesn't currently offer that in general, if it's because of my possibly specific implementation or if this package just hasn't implemented that so far?

class Value
{
public:
  virtual ~Value() = default;
};

class Array : public Value, public std::vector<Value*>
{
public:
  using std::vector<Value*>::vector;
....
};
....
  py::class_<Array, Value>(m, "Array", "")
....
    .def("__iter__", [](Array& array) {
      return py::make_iterator(array.begin(), array.end());
    }, py::keep_alive<0, 1>()); /* Keep vector alive while iterator is used */

Generates:

class Array(Value):
    def __iter__(self) -> typing.Iterator: ...

Is it possible to generate somethin like the following?

class Array(Value):
    def __iter__(self) -> typing.Iterator[Value]: ...
@sizmailov
Copy link
Owner

It's possible to render iterator types, but the changes were not accepted (yet) in upstream pybind11 repo due to introduced overhead:

Attempt 1: pybind/pybind11#2244
Attempt 2: pybind/pybind11#2371

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

No branches or pull requests

2 participants