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

**URL:** https://discourse.vtk.org/t/python-wrapping-of-std-vector-std-string-does-not-work-when-there-are-multiple-overloads/6517
**Category:** Development
**Created:** [August 31, 2021, 1:59pm UTC](https://discourse.vtk.org/t/python-wrapping-of-std-vector-std-string-does-not-work-when-there-are-multiple-overloads/6517 "2021-08-31T13:59:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [August 31, 2021, 1:59pm UTC](https://discourse.vtk.org/t/python-wrapping-of-std-vector-std-string-does-not-work-when-there-are-multiple-overloads/6517/1 "2021-08-31T13:59:05Z")

</div>

According to the [Python wrapper documentation](https://github.com/Kitware/VTK/blob/master/Wrapping/Python/README.md#stl-containers), 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:

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

```

Usage in Python:

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

```

→ Works well.

## Example of **incorrect** python wrapping

C++ header:

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

```

Usage in Python:

```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?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [August 31, 2021, 3:34pm UTC](https://discourse.vtk.org/t/python-wrapping-of-std-vector-std-string-does-not-work-when-there-are-multiple-overloads/6517/2 "2021-08-31T15:34:19Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [August 31, 2021, 4:41pm UTC](https://discourse.vtk.org/t/python-wrapping-of-std-vector-std-string-does-not-work-when-there-are-multiple-overloads/6517/3 "2021-08-31T16:41:53Z")

</div>

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