Skip to content

Commit

Permalink
ENH: Use ClassVar for class variable type hinting
Browse files Browse the repository at this point in the history
Use `ClassVar` for type hinting the `GaussianProcessRegressor`
`_parameter_constraints` class variable in child class.

Fixes:
```
src/nifreeze/model/gpr.py:156: error:
 Cannot override class variable (previously declared on base class "GaussianProcessRegressor") with instance variable  [misc]
```

raised for example in:
https://github.com/nipreps/nifreeze/actions/runs/12437972140/job/34728973936#step:8:71
  • Loading branch information
jhlegarreta committed Dec 22, 2024
1 parent ade884c commit 4b4caab
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/nifreeze/model/gpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from __future__ import annotations

from numbers import Integral, Real
from typing import Callable, Mapping, Sequence
from typing import Callable, ClassVar, Mapping, Sequence

import numpy as np
from scipy import optimize
Expand Down Expand Up @@ -153,7 +153,7 @@ class DiffusionGPR(GaussianProcessRegressor):
"""

_parameter_constraints: dict = {
_parameter_constraints: ClassVar[dict] = {
"kernel": [None, Kernel],
"alpha": [Interval(Real, 0, None, closed="left"), np.ndarray],
"optimizer": [StrOptions(SUPPORTED_OPTIMIZERS), callable, None],
Expand Down

0 comments on commit 4b4caab

Please sign in to comment.