# Python 3.8.1 deprecation warning

**URL:** https://discourse.vtk.org/t/python-3-8-1-deprecation-warning/2394
**Category:** Development
**Created:** [January 9, 2020, 5:42am UTC](https://discourse.vtk.org/t/python-3-8-1-deprecation-warning/2394 "2020-01-09T05:42:40Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 9, 2020, 5:42am UTC](https://discourse.vtk.org/t/python-3-8-1-deprecation-warning/2394/1 "2020-01-09T05:42:40Z")

</div>

If you look at the following code, there is a deprecation warning for:

```python
colors.SetColor("BkgColor", [0.3, 0.6, 0.3, 1.0])

```

As you can see from the code, I tried several alternatives including `vtk.vtkColor4ub` and `vtk.vtkColor4d`. The thinking here was that I could use either of these to circumvent the deprecation warning. However `vtk.vtkColor4d` raises an ambiguous call error. Does anyone know why this happens? I can’t see anything obvious in the actual VTK code.

Code is here:

```auto
#!/usr/bin/python

import vtk

def main():
    colors = vtk.vtkNamedColors()

    # Set the background color.
    # For Python 3.8.1
    # These generate: DeprecationWarning: an integer is required (got type float)
    # Implicit conversion to integers using __int__ is deprecated,
    # and may be removed in a future version of Python.
    colors.SetColor("BkgColor", [0.3, 0.6, 0.3, 1.0])
    colors.SetColor("BkgColor", 0.3, 0.6, 0.3, 1.0)
    # No deprecation message this is expected as the values are now integer
    colors.SetColor("BkgColor", [int(i * 255) for i in [0.3, 0.6, 0.3, 1.0]])
    # Try with vtk.vtkColor4ub or vtk.vtkColor4d
    x = vtk.vtkColor4ub([int(i * 255) for i in [0.3, 0.6, 0.3, 1.0]])
    colors.SetColor("BkgColor", x)
    # Fails with: TypeError: ambiguous call, multiple overloaded methods match the arguments
    # colors.SetColor("BkgColor", vtk.vtkColor4d(0.3, 0.6, 0.3, 1.0))

    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)
    renderer.SetBackground(colors.GetColor3d("BkgColor"))

    renderWindowInteractor.Initialize()
    renderWindow.Render()
    renderWindowInteractor.Start()

if __name__ == " __main__":
    main()

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [January 9, 2020, 2:16pm UTC](https://discourse.vtk.org/t/python-3-8-1-deprecation-warning/2394/2 "2020-01-09T14:16:43Z")

</div>

@dgobbi

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [January 9, 2020, 3:04pm UTC](https://discourse.vtk.org/t/python-3-8-1-deprecation-warning/2394/3 "2020-01-09T15:04:53Z")

</div>

Are you sure the error is thrown by `vtkColor4d` constructor? `vtkNamedColors::SetColor()` has several overloads too, hence it can also be the source of ambiguity, especially with “free floating” square brackets (which iterable type is being infered?). I’ve seen people using, for example, `List[]` in place of `[]`, to solve ambiguities.

---

<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: [January 9, 2020, 6:31pm UTC](https://discourse.vtk.org/t/python-3-8-1-deprecation-warning/2394/4 "2020-01-09T18:31:24Z")

</div>

I can fix the DeprecationWarning by adding an explicit check for the \_\_int\_\_() method to the wrapper code before it attempts the conversion.

The “ambiguous call” error also occurs with Python 3.7 and earlier versions. It shouldn’t happen, because vtkNamedColors has an an overload specifically for vtkColor4d. It might be a bug in the overload resolution code, I’ll investigate.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 9, 2020, 9:03pm UTC](https://discourse.vtk.org/t/python-3-8-1-deprecation-warning/2394/5 "2020-01-09T21:03:50Z")

</div>

Thankyou for looking into this @dgobbi.

---

<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: [January 9, 2020, 9:26pm UTC](https://discourse.vtk.org/t/python-3-8-1-deprecation-warning/2394/6 "2020-01-09T21:26:03Z")

</div>

See [!6379](https://gitlab.kitware.com/vtk/vtk/merge_requests/6379) for the DeprecationWarning fix.

I’ve found the reason for the ambiguity error, but will have to consider the best way to resolve it. The ambiguity is between these two methods:

```cpp
void SetColor(const vtkStdString& name, const double rgba[4]);
void SetColor(const vtkStdString& name, const vtkColor4d& rgba);

```

It occurs because the Python-wrapped `vtkColor4d` is a Python sequence of 4 floats, and can therefore satisfy either of these two overloads. Of course, the vtkColor4d overload should take precedence here.
