mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.88k stars 586 forks source link

Response is weird Array type #1216

Open Dreamsorcerer opened 3 years ago

Dreamsorcerer commented 3 years ago

When getting an ArrayOfString response back from an operation, I get some weird array object.

It says the type is zeep.objects.Array, and when iterating through the array, the values are meta keys:

>>> list(response)
['_value_1', 'arrayType', 'offset', 'id', 'href', '_attr_1']

The actual values are under response['_value_1'], but even this is a list of Elements, so to actually get a list of strings, you must:

[e.text for e in response["_value_1"]]

Expected behaviour is to be able to just return response or at worst list(response). Note that fixing this would be a breaking change and need a new major release.

Dreamsorcerer commented 3 years ago

Additionally, mypy thinks this is actually a list, so if I annotate the response with zeep.xsd.valueobjects.ArrayValue, then I get:

error: No overload variant of "__getitem__" of "list" matches argument type "str"  [call-overload]
note: Possible overload variants:
note:     def __getitem__(self, int) -> Any
note:     def __getitem__(self, slice) -> List[Any]

With code like:

response: zeep.xsd.valueobjects.ArrayValue = await client.service.Foo()
list_of_foo = [e.text for e in response["_value_1"]]