summaryrefslogtreecommitdiffstats
path: root/sqlglot/helper.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/helper.py')
-rw-r--r--sqlglot/helper.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/sqlglot/helper.py b/sqlglot/helper.py
index c3a23d3..42965d1 100644
--- a/sqlglot/helper.py
+++ b/sqlglot/helper.py
@@ -194,6 +194,24 @@ def split_num_words(value: str, sep: str, min_num_words: int, fill_from_start: b
return words + [None] * (min_num_words - len(words))
+def is_iterable(value: t.Any) -> bool:
+ """
+ Checks if the value is an iterable but does not include strings and bytes
+
+ Examples:
+ >>> is_iterable([1,2])
+ True
+ >>> is_iterable("test")
+ False
+
+ Args:
+ value: The value to check if it is an interable
+
+ Returns: Bool indicating if it is an iterable
+ """
+ return hasattr(value, "__iter__") and not isinstance(value, (str, bytes))
+
+
def flatten(values: t.Iterable[t.Union[t.Iterable[t.Any], t.Any]]) -> t.Generator[t.Any, None, None]:
"""
Flattens a list that can contain both iterables and non-iterable elements
@@ -211,7 +229,7 @@ def flatten(values: t.Iterable[t.Union[t.Iterable[t.Any], t.Any]]) -> t.Generato
Yields non-iterable elements (not including str or byte as iterable)
"""
for value in values:
- if hasattr(value, "__iter__") and not isinstance(value, (str, bytes)):
+ if is_iterable(value):
yield from flatten(value)
else:
yield value