fix(checker): improve unknown method message
This commit is contained in:
@@ -22,6 +22,10 @@ class Call:
|
|||||||
positional: list[TypedExpr]
|
positional: list[TypedExpr]
|
||||||
keywords: dict[str, TypedExpr]
|
keywords: dict[str, TypedExpr]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def subject(self) -> TypedExpr:
|
||||||
|
return (self.groupby_expr, self.groupby)
|
||||||
|
|
||||||
|
|
||||||
class ColumnGroupByMethodRegistry(MethodRegistry[Call]):
|
class ColumnGroupByMethodRegistry(MethodRegistry[Call]):
|
||||||
@method()
|
@method()
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ class Call:
|
|||||||
positional: list[TypedExpr]
|
positional: list[TypedExpr]
|
||||||
keywords: dict[str, TypedExpr]
|
keywords: dict[str, TypedExpr]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def subject(self) -> TypedExpr:
|
||||||
|
return (self.column_expr, self.column)
|
||||||
|
|
||||||
|
|
||||||
class ColumnMethodRegistry(MethodRegistry[Call]):
|
class ColumnMethodRegistry(MethodRegistry[Call]):
|
||||||
def _element_binary_op(self, call: Call, method: str) -> ColumnType:
|
def _element_binary_op(self, call: Call, method: str) -> ColumnType:
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ class Call:
|
|||||||
positional: list[TypedExpr]
|
positional: list[TypedExpr]
|
||||||
keywords: dict[str, TypedExpr]
|
keywords: dict[str, TypedExpr]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def subject(self) -> TypedExpr:
|
||||||
|
return (self.groupby_expr, self.groupby)
|
||||||
|
|
||||||
|
|
||||||
class FrameGroupByMethodRegistry(MethodRegistry[Call]):
|
class FrameGroupByMethodRegistry(MethodRegistry[Call]):
|
||||||
@method()
|
@method()
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ class Call:
|
|||||||
positional: list[TypedExpr]
|
positional: list[TypedExpr]
|
||||||
keywords: dict[str, TypedExpr]
|
keywords: dict[str, TypedExpr]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def subject(self) -> TypedExpr:
|
||||||
|
return (self.frame_expr, self.frame)
|
||||||
|
|
||||||
|
|
||||||
class FrameMethodRegistry(MethodRegistry[Call]):
|
class FrameMethodRegistry(MethodRegistry[Call]):
|
||||||
def _get_method_result(
|
def _get_method_result(
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from midas.checker.types import Type, UnknownType
|
|||||||
from midas.generator.collector import AssertionCollector
|
from midas.generator.collector import AssertionCollector
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from midas.checker.python import PythonTyper
|
from midas.checker.python import PythonTyper, TypedExpr
|
||||||
|
|
||||||
|
|
||||||
class _MethodRegistryMeta(type):
|
class _MethodRegistryMeta(type):
|
||||||
@@ -41,12 +41,18 @@ class _MethodRegistryMeta(type):
|
|||||||
return new_class
|
return new_class
|
||||||
|
|
||||||
|
|
||||||
class HasLocation(Protocol):
|
class MethodCall(Protocol):
|
||||||
@property
|
@property
|
||||||
def location(self) -> Location: ...
|
def location(self) -> Location: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def call_expr(self) -> p.Expr: ...
|
||||||
|
|
||||||
T = TypeVar("T", bound=HasLocation)
|
@property
|
||||||
|
def subject(self) -> TypedExpr: ...
|
||||||
|
|
||||||
|
|
||||||
|
T = TypeVar("T", bound=MethodCall)
|
||||||
|
|
||||||
|
|
||||||
class MethodRegistry(Generic[T], metaclass=_MethodRegistryMeta):
|
class MethodRegistry(Generic[T], metaclass=_MethodRegistryMeta):
|
||||||
@@ -72,7 +78,9 @@ class MethodRegistry(Generic[T], metaclass=_MethodRegistryMeta):
|
|||||||
def call(self, method: str, call: T) -> Type:
|
def call(self, method: str, call: T) -> Type:
|
||||||
func: Optional[Callable[[Self, T], Type]] = self._methods.get(method)
|
func: Optional[Callable[[Self, T], Type]] = self._methods.get(method)
|
||||||
if func is None:
|
if func is None:
|
||||||
self.reporter.warning(call.location, f"Unknown method {method}")
|
self.reporter.warning(
|
||||||
|
call.location, f"Unknown method {method} on {call.subject[1]}"
|
||||||
|
)
|
||||||
return UnknownType()
|
return UnknownType()
|
||||||
return func(self, call)
|
return func(self, call)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user