From 2e5a71c765b8046f5538a4e51be3da42b98056a0 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 1 Jan 2019 18:01:37 -0800 Subject: [PATCH] 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. --- voussoirkit/sqlhelpers.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/voussoirkit/sqlhelpers.py b/voussoirkit/sqlhelpers.py index 5ae55f8..7533d20 100644 --- a/voussoirkit/sqlhelpers.py +++ b/voussoirkit/sqlhelpers.py @@ -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