smiley/steamapi

APIResponse-wrapping breaks if dict eventually contains a list of non-dicts

smiley opened this issue · 1 comments

When APIResponse is given a dictionary to wrap, if one of the values (wherever in the tree) is a list of non-dictionary objects, wrapping breaks because of trying to enumerate it like a dictionary.

We either get an error for wrongful iteration ("string indices must be integers, not str") or an error for even trying to iterate. ("'int' object is not iterable")

This can be reproduced with either example:

Wrongful iteration

>>> from steamapi import *
>>> core.APIResponse({'a': 1, 'b': 2, 'c': ['this', 'will', 'break']})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "steamapi\core.py", line 433, in __init__
    self._real_dictionary[item] = [APIResponse(entry) for entry in father_dict[item]]
  File "steamapi\core.py", line 430, in __init__
    if type(father_dict[item]) is dict:
TypeError: string indices must be integers, not str

Not iterable

>>> from steamapi import *
>>> core.APIResponse({'a': 1, 'b': 2, 'c': [123]})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "steamapi\core.py", line 433, in __init__
    self._real_dictionary[item] = [APIResponse(entry) for entry in father_dict[item]]
  File "steamapi\core.py", line 429, in __init__
    for item in father_dict:
TypeError: 'int' object is not iterable

Fixed in master.