Bug
dumps() raises TypeError: argument of type 'int' is not a container or iterable when serializing a list that contains non-string scalar values such as integers or floats.
Root cause
In _dump, when iterating list items, non-dict items are passed directly to _escape():
yield '%s%s\n' % (' ' * (indent + 2), _escape(subvalue))
_escape() does for ch in _ESCAPE_CHARACTERS: if ch in k — which fails when k is an int (or any non-string type) because in on a string requires the left operand to also be a string.
Reproducer
import structprop
structprop.dumps({"ids": [1, 2, 3]})
# TypeError: argument of type 'int' is not a container or iterable
Fix
_escape should coerce its argument to str before testing membership, or _dump should coerce non-string list items to strings before passing them to _escape:
def _escape(k):
k = str(k)
for ch in _ESCAPE_CHARACTERS:
if ch in k:
return '"%s"' % (k,)
return k
Bug
dumps()raisesTypeError: argument of type 'int' is not a container or iterablewhen serializing a list that contains non-string scalar values such as integers or floats.Root cause
In
_dump, when iterating list items, non-dict items are passed directly to_escape():_escape()doesfor ch in _ESCAPE_CHARACTERS: if ch in k— which fails whenkis anint(or any non-string type) becauseinon a string requires the left operand to also be a string.Reproducer
Fix
_escapeshould coerce its argument tostrbefore testing membership, or_dumpshould coerce non-string list items to strings before passing them to_escape: