fix(checker): catch UndefinedMethodException where needed

This commit is contained in:
2026-07-10 11:00:23 +02:00
parent e302ed2377
commit 00fdda5034
3 changed files with 20 additions and 8 deletions

View File

@@ -86,6 +86,9 @@ class ColumnGroupByMethodRegistry(MethodRegistry[Call]):
# TODO: maybe better to filter arguments and pass some, in case the # TODO: maybe better to filter arguments and pass some, in case the
# return type depends on them # return type depends on them
# Don't catch UndefinedMethodException because all aggregation
# methods should be defined on columns too
returns: Type = self.typer.call_method( returns: Type = self.typer.call_method(
location=call.location, location=call.location,
call_expr=call.call_expr, call_expr=call.call_expr,

View File

@@ -53,6 +53,8 @@ class FrameGroupByMethodRegistry(MethodRegistry[Call]):
for column in call.groupby.frame.columns: for column in call.groupby.frame.columns:
with self.reporter.with_context(f"in column '{column.name}'"): with self.reporter.with_context(f"in column '{column.name}'"):
column_groupby: ColumnGroupBy = ColumnGroupBy(column=column.type) column_groupby: ColumnGroupBy = ColumnGroupBy(column=column.type)
# Don't catch UndefinedMethodException because all aggregation
# methods should be defined on columns too
result_type: Type = self.typer.call_method( result_type: Type = self.typer.call_method(
location=call.location, location=call.location,
call_expr=call.call_expr, call_expr=call.call_expr,

View File

@@ -772,6 +772,7 @@ class PythonTyper(
match expr.callee: match expr.callee:
case p.GetExpr(object=obj, name=method): case p.GetExpr(object=obj, name=method):
obj_type: Type = self.type_of(obj) obj_type: Type = self.type_of(obj)
try:
return self.call_method( return self.call_method(
location=expr.location, location=expr.location,
call_expr=expr, call_expr=expr,
@@ -780,6 +781,12 @@ class PythonTyper(
positional=positional, positional=positional,
keywords=keywords, keywords=keywords,
) )
except UndefinedMethodException:
self.reporter.error(
expr.location,
f"Unknown method {method} on type {obj_type}",
)
return UnknownType()
callee: Type = self.type_of(expr.callee) callee: Type = self.type_of(expr.callee)
result: CallResult = self.dispatcher.get_result( result: CallResult = self.dispatcher.get_result(