Skip to content

Commit

Permalink
Fix: satisfy mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas committed Oct 14, 2024
1 parent eeae25e commit b26a3f6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
11 changes: 7 additions & 4 deletions sqlglot/dialects/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,18 @@ def _parse_function(
)

if parts:
params = self._parse_func_params(func)
anon_func: exp.Anonymous = t.cast(exp.Anonymous, func)
params = self._parse_func_params(anon_func)

kwargs = {
"this": func.this,
"expressions": func.expressions,
"this": anon_func.this,
"expressions": anon_func.expressions,
}
if parts[1]:
kwargs["parts"] = parts
exp_class = exp.CombinedParameterizedAgg if params else exp.CombinedAggFunc
exp_class: t.Type[exp.Expression] = (
exp.CombinedParameterizedAgg if params else exp.CombinedAggFunc
)
else:
exp_class = exp.ParameterizedAgg if params else exp.AnonymousAggFunc

Expand Down
4 changes: 2 additions & 2 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ def depth(self) -> int:
def iter_expressions(self, reverse: bool = False) -> t.Iterator[Expression]:
"""Yields the key and expression for all arguments, exploding list args."""
# remove tuple when python 3.7 is deprecated
for vs in reversed(tuple(self.args.values())) if reverse else self.args.values():
for vs in reversed(tuple(self.args.values())) if reverse else self.args.values(): # type: ignore
if type(vs) is list:
for v in reversed(vs) if reverse else vs:
for v in reversed(vs) if reverse else vs: # type: ignore
if hasattr(v, "parent"):
yield v
else:
Expand Down
9 changes: 6 additions & 3 deletions sqlglot/optimizer/annotate_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,18 @@ def _annotate_args(self, expression: E) -> E:

def _maybe_coerce(
self, type1: exp.DataType | exp.DataType.Type, type2: exp.DataType | exp.DataType.Type
) -> exp.DataType:
) -> exp.DataType.Type:
type1_value = type1.this if isinstance(type1, exp.DataType) else type1
type2_value = type2.this if isinstance(type2, exp.DataType) else type2

# We propagate the UNKNOWN type upwards if found
if exp.DataType.Type.UNKNOWN in (type1_value, type2_value):
return exp.DataType.build("unknown")
return exp.DataType.Type.UNKNOWN

return type2_value if type2_value in self.coerces_to.get(type1_value, {}) else type1_value
return t.cast(
exp.DataType.Type,
type2_value if type2_value in self.coerces_to.get(type1_value, {}) else type1_value,
)

def _annotate_binary(self, expression: B) -> B:
self._annotate_args(expression)
Expand Down
2 changes: 1 addition & 1 deletion sqlglot/optimizer/qualify_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def _expand_stars(
) -> None:
"""Expand stars to lists of column selections"""

new_selections = []
new_selections: t.List[exp.Expression] = []
except_columns: t.Dict[int, t.Set[str]] = {}
replace_columns: t.Dict[int, t.Dict[str, exp.Alias]] = {}
rename_columns: t.Dict[int, t.Dict[str, str]] = {}
Expand Down

0 comments on commit b26a3f6

Please sign in to comment.