Skip to content

Commit 94013a2

Browse files
authored
Refactor: simplify _expression_only_args helper in diff module (#4251)
1 parent 6f32e53 commit 94013a2

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

sqlglot/diff.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from heapq import heappop, heappush
1313

1414
from sqlglot import Dialect, expressions as exp
15-
from sqlglot.helper import ensure_list
1615

1716
if t.TYPE_CHECKING:
1817
from sqlglot.dialects.dialect import DialectType
@@ -372,16 +371,12 @@ def _parent_similarity_score(
372371
return 1 + _parent_similarity_score(source.parent, target.parent)
373372

374373

375-
def _expression_only_args(expression: exp.Expression) -> t.List[exp.Expression]:
376-
args: t.List[t.Union[exp.Expression, t.List]] = []
377-
if expression:
378-
for a in expression.args.values():
379-
args.extend(ensure_list(a))
380-
return [
381-
a
382-
for a in args
383-
if isinstance(a, exp.Expression) and not isinstance(a, IGNORED_LEAF_EXPRESSION_TYPES)
384-
]
374+
def _expression_only_args(expression: exp.Expression) -> t.Iterator[exp.Expression]:
375+
yield from (
376+
arg
377+
for arg in expression.iter_expressions()
378+
if not isinstance(arg, IGNORED_LEAF_EXPRESSION_TYPES)
379+
)
385380

386381

387382
def _lcs(

0 commit comments

Comments
 (0)