Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Nov 29, 2022
1 parent a338ee9 commit 19d26df
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions openfisca_core/holders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@

from .helpers import set_input_dispatch_by_period, set_input_divide_by_period # noqa: F401
from .holder import Holder # noqa: F401
from .memory_usage import MemoryUsage # noqa: F401
4 changes: 2 additions & 2 deletions openfisca_core/holders/holder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Sequence, Union
from typing import Any, Optional, Sequence, Union

import os
import warnings
Expand Down Expand Up @@ -166,7 +166,7 @@ def set_input(
self,
period: types.Period,
array: Union[numpy.ndarray, Sequence[Any]],
) -> numpy.ndarray:
) -> Optional[numpy.ndarray]:
"""Set a Variable's array of values of a given Period.
Args:
Expand Down
10 changes: 1 addition & 9 deletions openfisca_core/populations/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy

from openfisca_core import periods, projectors
from openfisca_core.holders import Holder
from openfisca_core.holders import Holder, MemoryUsage
from openfisca_core.projectors import Projector
from openfisca_core.types import Array, Entity, Period, Role, Simulation

Expand Down Expand Up @@ -272,11 +272,3 @@ class Calculate(NamedTuple):
class MemoryUsageByVariable(TypedDict, total = False):
by_variable: Dict[str, MemoryUsage]
total_nb_bytes: int


class MemoryUsage(TypedDict, total = False):
cell_size: int
dtype: numpy.dtype
nb_arrays: int
nb_cells_by_array: int
total_nb_bytes: int
9 changes: 9 additions & 0 deletions openfisca_core/types/_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ def get_memory_usage(self) -> Any:
"""Abstract method."""


class Instant(Protocol):
"""Instant protocol."""


@typing_extensions.runtime_checkable
class Period(Protocol):
"""Period protocol."""

@property
@abc.abstractmethod
def unit(self) -> Instant:
"""Abstract method."""


class Population(Protocol):
"""Population protocol."""
Expand Down

0 comments on commit 19d26df

Please sign in to comment.