Define listify seperately so you can call with any iterable.

The literal function will still be a bit more strict on the types
it accepts, but if you have something that you know is okay
to iterate you can call listify directly.
This commit is contained in:
Ethan Dalool 2019-01-01 18:01:37 -08:00
parent 649011c60d
commit 2e5a71c765

View file

@ -1,3 +1,5 @@
import types
def delete_filler(pairs):
'''
Manually aligning the bindings for DELETE statements is annoying.
@ -142,10 +144,13 @@ def literal(item):
item = ''.join(hex_byte(byte) for byte in item)
return f"X'{item}'"
elif isinstance(item, (list, tuple, set)):
output = ', '.join(literal(element) for element in item)
output = f'({output})'
return output
elif isinstance(item, (list, tuple, set, types.GeneratorType)):
return listify(item)
else:
raise ValueError(f'Unrecognized type {type(item)} {item}.')
def listify(items):
output = ', '.join(literal(item) for item in items)
output = f'({output})'
return output