Skip to content

Commit 681016f

Browse files
committed
ENH: Remove type hint in overriden diag methods
Remove type hint in overriden `diag` methods in kernel classes: it is unsafe to override a method with a more specific argument type, as it violates the Liskov substitution principle. Fixes: ``` src/nifreeze/model/gpr.py:335: error: Argument 1 of "diag" is incompatible with supertype "Kernel"; supertype defines the argument type as "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]" [override] src/nifreeze/model/gpr.py:335: note: This violates the Liskov substitution principle src/nifreeze/model/gpr.py:335: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides src/nifreeze/model/gpr.py:445: error: Argument 1 of "diag" is incompatible with supertype "Kernel"; supertype defines the argument type as "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]" [override] src/nifreeze/model/gpr.py:445: note: This violates the Liskov substitution principle src/nifreeze/model/gpr.py:335: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides ``` raised for example in: https://github.com/nipreps/nifreeze/actions/runs/12437972140/job/34728973936#step:8:93 Documentation: https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
1 parent de2b304 commit 681016f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/nifreeze/model/gpr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def __call__(
332332

333333
return self.beta_l * C_theta, K_gradient
334334

335-
def diag(self, X: np.ndarray) -> np.ndarray:
335+
def diag(self, X) -> np.ndarray:
336336
"""Returns the diagonal of the kernel k(X, X).
337337
338338
The result of this method is identical to np.diag(self(X)); however,
@@ -442,7 +442,7 @@ def __call__(
442442

443443
return self.beta_l * C_theta, K_gradient
444444

445-
def diag(self, X: np.ndarray) -> np.ndarray:
445+
def diag(self, X) -> np.ndarray:
446446
"""Returns the diagonal of the kernel k(X, X).
447447
448448
The result of this method is identical to np.diag(self(X)); however,

0 commit comments

Comments
 (0)