Fix Version/s: None
Currently pybind11 uses an explicit mapping:
- std::vector, std::list <-> list
- std::tuple(, std::pair) <-> tuple
The problem of that lies in the two-way conversion. This means that wrapped C++ functions with vector or list arguments cannot accept a Python tuple and functions with tuple (or pair) parameters cannot accept a Python list. The same holds true for any other sequence type.
This ticket aims to fix this in upstream pybind11.
Forgot to mention that this also works for std::list, not just std::vector.
I have no objection to the aims of this issue or, at a superficial level, to the code changes. I don't have the expertise — or the opportunity to acquire it in the near future — to understand the details of the implementation, but I assume that the upstream pybind11 project will only accept it if they're happy with it.
I was surprised by the lack of documentation, but it seems that upstream's attitude to this is basically "see the test suite for examples", so maybe this is adequate.
Happy for you to go ahead and submit this upstream.
Turned out to be easy for std::vector but potentially harder for the other C++ types because they are deeper integrated in the internals of pybind11.
So, proposing to limit this ticket to std::vector. This is also by far the most used case in our codebase.
This means that functions that accept a pair or tuple continue to only be callable with a Python tuple, but functions that accept a vector can accept any sequence type.
If needed later we can always revisit.
The PR is at https://github.com/lsst-dm/pybind11/pull/4 and is ready for submitting to upstream after internal review (but before closing this ticket).
The main possible stumbling block I see, for acceptance upstream, is that when functions are overloaded on vector and tuple (or pair) now the vector one will shadow it if it comes first in the overload list. But I don't see a way out here. And in any case this is arguably bad design. Plus the same problem already exists between tuple and pair.