Python wrapping of `std::vector<std::string>` does not work when there are multiple overloads

According to the Python wrapper documentation, I can pass Python string list to methods that take std::vector<std::string> (or as reference/const reference) as input. This works very nicely, except when we have multiple methods with the same name.

Example of correct python wrapping

C++ header:

  bool Test(const std::vector<std::string>& values);

Usage in Python:

>>> slicer.modules.segmentations.logic().Test(["aaa", "bbb", "ttt"])
True

→ Works well.

Example of incorrect python wrapping

C++ header:

  bool Test(const std::vector<std::string>& values);
  bool Test(vtkStringArray* values);

Usage in Python:

>>> slicer.modules.segmentations.logic().Test(["aaa", "bbb", "ttt"])
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: arguments do not match any overloaded methods

>>> help(slicer.modules.segmentations.logic().Test)
Help on built-in function Test:

Test(...) method of vtkSlicerSegmentationsModuleLogic.vtkSlicerSegmentationsModuleLogic instance
    V.Test(Stvector_ISt6stringE) -> bool
    C++: static bool Test(const std::vector<std::string> values)
    V.Test(vtkStringArray) -> bool
    C++: static bool Test(vtkStringArray *values)

→ The same method is now not found.

Failure to use overloaded methods is an issue because for many methods we added alternative versions that use vtkStringArray instead of std::vector<std::string> for Python compatibility. Now these alternative versions seem to break the wrapping.

@dgobbi Is this error known and/or expected? Could you check if this could be fixed easily?

Thanks for pointing this out. It is exactly what it seems: the wrappers have a bug in overload resolution for methods with std::vector parameters. I’ve created a simple example to reproduce the bug on my machine, it looks like it will be easy to fix.

Awesome, thank you. The fix will help a lot in making our API more Python-friendly.