Skip to content

Commit 91090cc

Browse files
committed
TL: tentative for better static typing
1 parent a1274d8 commit 91090cc

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

qmat/qcoeff/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
- :class:`butcher` : Runge-Kutta based (Butcher tables)
1212
"""
1313
import numpy as np
14+
from typing import Type, TypeVar, Dict
1415

1516
from qmat.utils import checkOverriding, storeClass, importAll
1617
from qmat.lagrange import LagrangeApproximation
1718

19+
T = TypeVar("T")
20+
21+
1822
class QGenerator(object):
1923
"""Base abstract class for all :math:`Q`-coefficients generators"""
2024

@@ -205,10 +209,10 @@ def errorDahlquist(self, lam, u0, T, nSteps, uNum=None, useEmbeddedWeights=False
205209
return np.linalg.norm(uNum-uExact, ord=np.inf)
206210

207211

208-
Q_GENERATORS = {}
212+
Q_GENERATORS: Dict[str, QGenerator] = {}
209213
"""Dictionary containing all specialized :class:`QGenerator` classes, with all their aliases"""
210214

211-
def register(cls:QGenerator)->QGenerator:
215+
def register(cls: Type[T]) -> Type[T]:
212216
"""Class decorator to register a specialized :class:`QGenerator` class in qmat"""
213217
# Check for correct overriding
214218
for name in ["nodes", "Q", "weights", "order"]:

qmat/qdelta/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
"""
1414
import inspect
1515
import numpy as np
16+
from typing import Type, TypeVar, Dict
1617

1718
from qmat.utils import checkOverriding, storeClass, importAll, checkGenericConstr
1819

20+
T = TypeVar("T")
21+
1922

2023
class QDeltaGenerator(object):
2124
r"""
@@ -154,10 +157,10 @@ def genCoeffs(self, k=None, form="Z2N", dTau=False):
154157
return out if len(out) > 1 else out[0]
155158

156159

157-
QDELTA_GENERATORS = {}
160+
QDELTA_GENERATORS: Dict[str, QDeltaGenerator] = {}
158161
"""Dictionary containing all specialized :class:`QDeltaGenerator` classes"""
159162

160-
def register(cls:QDeltaGenerator)->QDeltaGenerator:
163+
def register(cls: Type[T]) -> Type[T]:
161164
"""Class decorator to register a specialized :class:`QDeltaGenerator` class in `qmat`"""
162165
checkGenericConstr(cls)
163166
checkOverriding(cls, "computeQDelta", isProperty=False)

0 commit comments

Comments
 (0)