Skip to content

Commit 14a7998

Browse files
committed
REF: Inherit base model class from ABC to enforece native abstraction
Inherit base model class from `ABC` to enforece native abstraction. Fixes: ``` Abstract methods are allowed in classes whose metaclass is 'ABCMeta' ``` raised locally by the IDE.
1 parent bb3d129 commit 14a7998

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/nifreeze/model/base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#
2323
"""Base infrastructure for nifreeze's models."""
2424

25-
from abc import abstractmethod
25+
from abc import ABC, ABCMeta, abstractmethod
2626
from warnings import warn
2727

2828
import numpy as np
@@ -76,7 +76,7 @@ def init(model: str | None = None, **kwargs):
7676
raise NotImplementedError(f"Unsupported model <{model}>.")
7777

7878

79-
class BaseModel:
79+
class BaseModel(ABC):
8080
"""
8181
Defines the interface and default methods.
8282
@@ -87,6 +87,8 @@ class BaseModel:
8787
8888
"""
8989

90+
__metaclass__ = ABCMeta
91+
9092
__slots__ = ("_dataset", "_locked_fit")
9193

9294
def __init__(self, dataset, **kwargs):
@@ -99,7 +101,7 @@ def __init__(self, dataset, **kwargs):
99101
warn(mask_absence_warn_msg, stacklevel=2)
100102

101103
@abstractmethod
102-
def fit_predict(self, index: int | None = None, **kwargs) -> np.ndarray:
104+
def fit_predict(self, index: int | None = None, **kwargs):
103105
"""
104106
Fit and predict the indicated index of the dataset (abstract signature).
105107
@@ -115,7 +117,7 @@ def fit_predict(self, index: int | None = None, **kwargs) -> np.ndarray:
115117
If ``None``, no prediction will be executed.
116118
117119
"""
118-
raise NotImplementedError("Cannot call fit_predict() on a BaseModel instance.")
120+
return
119121

120122

121123
class TrivialModel(BaseModel):

0 commit comments

Comments
 (0)