diff --git a/docker/types/services.py b/docker/types/services.py index 821115411..fd831dd55 100644 --- a/docker/types/services.py +++ b/docker/types/services.py @@ -560,11 +560,9 @@ def __init__(self, mode=None, ports=None): def convert_service_ports(ports): - if isinstance(ports, list): - return ports if not isinstance(ports, dict): raise TypeError( - 'Invalid type for ports, expected dict or list' + 'Invalid type for ports, expected dict' ) result = [] diff --git a/tests/unit/dockertypes_test.py b/tests/unit/dockertypes_test.py index 03e7d2eda..c6b3e1932 100644 --- a/tests/unit/dockertypes_test.py +++ b/tests/unit/dockertypes_test.py @@ -491,3 +491,9 @@ def test_convert_service_ports_multiple(self): } in converted_ports assert len(converted_ports) == 3 + + def test_convert_service_ports_wrong_ports_type(self): + ports = 'ports_as_string' + + with pytest.raises(TypeError): + convert_service_ports(ports)