Skip to content

Commit

Permalink
chore(types): re-order types per module
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Sep 16, 2024
1 parent bbc402f commit 077a4af
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 191 deletions.
130 changes: 76 additions & 54 deletions openfisca_core/types/_domain.py → openfisca_core/types.py
Original file line number Diff line number Diff line change
@@ -1,146 +1,168 @@
from __future__ import annotations

import typing_extensions
from typing import Any, Optional
from typing_extensions import Protocol
from collections.abc import Sequence
from numpy.typing import NDArray
from typing import Any, TypeVar
from typing_extensions import Protocol, TypeAlias

import abc

import numpy

N = TypeVar("N", bound=numpy.generic, covariant=True)

class Entity(Protocol):
"""Entity protocol."""
#: Type representing an numpy array.
Array: TypeAlias = NDArray[N]

L = TypeVar("L")

#: Type representing an array-like object.
ArrayLike: TypeAlias = Sequence[L]

#: Type variable representing an error.
E = TypeVar("E", covariant=True)

#: Type variable representing a value.
A = TypeVar("A", covariant=True)


# Entities


class Entity(Protocol):
key: Any
plural: Any

@abc.abstractmethod
def check_role_validity(self, role: Any) -> None:
"""Abstract method."""
...

@abc.abstractmethod
def check_variable_defined_for_entity(self, variable_name: Any) -> None:
"""Abstract method."""
...

@abc.abstractmethod
def get_variable(
self,
variable_name: Any,
check_existence: Any = ...,
) -> Optional[Any]:
"""Abstract method."""
) -> Any | None:
...


class Formula(Protocol):
"""Formula protocol."""
class Role(Protocol):
entity: Any
subroles: Any

@abc.abstractmethod
def __call__(
self,
population: Population,
instant: Instant,
params: Params,
) -> numpy.ndarray:
"""Abstract method."""

# Holders

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

class Holder(Protocol):
@abc.abstractmethod
def clone(self, population: Any) -> Holder:
"""Abstract method."""
...

@abc.abstractmethod
def get_memory_usage(self) -> Any:
"""Abstract method."""
...


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


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


class Params(Protocol):
"""Params protocol."""
# Periods

@abc.abstractmethod
def __call__(self, instant: Instant) -> ParameterNodeAtInstant:
"""Abstract method."""

class Instant(Protocol):
...


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

@property
@abc.abstractmethod
def start(self) -> Any:
"""Abstract method."""
...

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


class Population(Protocol):
"""Population protocol."""
# Populations


class Population(Protocol):
entity: Any

@abc.abstractmethod
def get_holder(self, variable_name: Any) -> Any:
"""Abstract method."""

...

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

entity: Any
subroles: Any
# Simulations


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

@abc.abstractmethod
def calculate(self, variable_name: Any, period: Any) -> Any:
"""Abstract method."""
...

@abc.abstractmethod
def calculate_add(self, variable_name: Any, period: Any) -> Any:
"""Abstract method."""
...

@abc.abstractmethod
def calculate_divide(self, variable_name: Any, period: Any) -> Any:
"""Abstract method."""
...

@abc.abstractmethod
def get_population(self, plural: Optional[Any]) -> Any:
"""Abstract method."""
def get_population(self, plural: Any | None) -> Any:
...


class TaxBenefitSystem(Protocol):
"""TaxBenefitSystem protocol."""
# Tax-Benefit systems


class TaxBenefitSystem(Protocol):
person_entity: Any

@abc.abstractmethod
def get_variable(
self,
variable_name: Any,
check_existence: Any = ...,
) -> Optional[Any]:
) -> Any | None:
"""Abstract method."""


class Variable(Protocol):
"""Variable protocol."""
# Variables


class Variable(Protocol):
entity: Any


class Formula(Protocol):
@abc.abstractmethod
def __call__(
self,
population: Population,
instant: Instant,
params: Params,
) -> Array[Any]:
...


class Params(Protocol):
@abc.abstractmethod
def __call__(self, instant: Instant) -> ParameterNodeAtInstant:
...
83 changes: 0 additions & 83 deletions openfisca_core/types/__init__.py

This file was deleted.

54 changes: 0 additions & 54 deletions openfisca_core/types/_data.py

This file was deleted.

0 comments on commit 077a4af

Please sign in to comment.