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:
parent
649011c60d
commit
2e5a71c765
1 changed files with 9 additions and 4 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import types
|
||||||
|
|
||||||
def delete_filler(pairs):
|
def delete_filler(pairs):
|
||||||
'''
|
'''
|
||||||
Manually aligning the bindings for DELETE statements is annoying.
|
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)
|
item = ''.join(hex_byte(byte) for byte in item)
|
||||||
return f"X'{item}'"
|
return f"X'{item}'"
|
||||||
|
|
||||||
elif isinstance(item, (list, tuple, set)):
|
elif isinstance(item, (list, tuple, set, types.GeneratorType)):
|
||||||
output = ', '.join(literal(element) for element in item)
|
return listify(item)
|
||||||
output = f'({output})'
|
|
||||||
return output
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'Unrecognized type {type(item)} {item}.')
|
raise ValueError(f'Unrecognized type {type(item)} {item}.')
|
||||||
|
|
||||||
|
def listify(items):
|
||||||
|
output = ', '.join(literal(item) for item in items)
|
||||||
|
output = f'({output})'
|
||||||
|
return output
|
||||||
|
|
Loading…
Reference in a new issue