Data types and protocols used by OpenFisca Core.
The type definitions included in this sub-package are intented for contributors, to help them better understand and document contracts and expected behaviours.
How imports are being used today:
from openfisca_core.types import * # Bad from openfisca_core.types.data_types.arrays import ArrayLike # Bad
The previous examples provoke cyclic dependency problems, that prevents us from modularizing the different components of the library, so as to make them easier to test and to maintain.
How could them be used after the next major release:
from openfisca_core.types import ArrayLike ArrayLike # Good: import types as publicly exposed
Type of any castable to
>>> ArrayLike[float] typing.Union[numpy.ndarray, typing.Sequence[float]]
>>> ArrayLike[str] typing.Union[numpy.ndarray, typing.Sequence[str]]
It is possible since numpy version 1.21 to specify the type of an array, thanks to numpy.typing.NDArray:
from numpy.typing import NDArray NDArray[numpy.float64]
New in version 35.5.0.
Changed in version 35.6.0: Moved to