diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-10-25 16:01:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-10-25 16:01:47 +0000 |
commit | be33e8ff4eed68ad217f9ef6ad535206df4129f8 (patch) | |
tree | 752695efdccc8387e37e233c900ce7c3c8f1aaff /sqlglot/helper.py | |
parent | Releasing debian version 9.0.1-1. (diff) | |
download | sqlglot-be33e8ff4eed68ad217f9ef6ad535206df4129f8.tar.xz sqlglot-be33e8ff4eed68ad217f9ef6ad535206df4129f8.zip |
Merging upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/helper.py')
-rw-r--r-- | sqlglot/helper.py | 20 |
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 |