>>> # Test that all anomaly detectors implement abstract predict.
>>> assert "_predict" in estimator_class.__dict__
E AssertionError
This, however, just checks within the final class definition and ignores any potential implementations in the class hierarchy. Thus, in wrapper-land, we are required to overwrite these methods only to call the super-implementation, e.g.:
I would like to avoid the boilerplate code and reduce the wrapper to the class-definition, documentation, and constructor.
Suggest a potential alternative/fix
Python's abstract base classes already provide a way to enforce that abstract methods must be implemented. Otherwise, the instantiation of the class fails.
If we ensure that all our base classes inherit from abc.ABC and annotate their abstract methods with abc.abstractmethod, we can remove the testing for implementations of _fit/_predict/_fit_predict, and just test the instantiation of the estimator to not raise a TypeError: Can't instantiate abstract class XYZ with abstract method _xyz.
[x] ensure that all base classes inherit from abc.ABC
[ ] annotate all abstract methods with abc.abstractmethod (at least _predict, _fit, _fit_predict)
[ ] change testing framework (remove all checks for implementations of the abstract methods; add a test that instantiates an estimator and provides a proper error message)
Describe the issue
As discussed in https://github.com/aeon-toolkit/aeon/pull/2118#discussion_r1796538246 and Slack, our current testing framework checks that every estimator class has an implementation for
_fit
/_predict
/_fit_predict
usingThis, however, just checks within the final class definition and ignores any potential implementations in the class hierarchy. Thus, in wrapper-land, we are required to overwrite these methods only to call the super-implementation, e.g.:
I would like to avoid the boilerplate code and reduce the wrapper to the class-definition, documentation, and constructor.
Suggest a potential alternative/fix
Python's abstract base classes already provide a way to enforce that abstract methods must be implemented. Otherwise, the instantiation of the class fails.
If we ensure that all our base classes inherit from
abc.ABC
and annotate their abstract methods withabc.abstractmethod
, we can remove the testing for implementations of_fit
/_predict
/_fit_predict
, and just test the instantiation of the estimator to not raise aTypeError: Can't instantiate abstract class XYZ with abstract method _xyz
.abc.ABC
abc.abstractmethod
(at least_predict
,_fit
,_fit_predict
)Additional context
No response