-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: document get_projector_from_shortcut() (#1197)
- Loading branch information
Showing
22 changed files
with
510 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from __future__ import annotations | ||
|
||
from abc import abstractmethod | ||
from openfisca_core.types import TaxBenefitSystem, Variable | ||
from typing import Any | ||
|
||
import os | ||
|
||
from .role import Role | ||
from .typing import Entity | ||
|
||
|
||
class _CoreEntity: | ||
"""Base class to build entities from.""" | ||
|
||
#: A key to identify the entity. | ||
key: str | ||
|
||
#: The ``key``, pluralised. | ||
plural: str | None | ||
|
||
#: A summary description. | ||
label: str | None | ||
|
||
#: A full description. | ||
doc: str | None | ||
|
||
#: Whether the entity is a person or not. | ||
is_person: bool | ||
|
||
#: A TaxBenefitSystem instance. | ||
_tax_benefit_system: TaxBenefitSystem | None = None | ||
|
||
@abstractmethod | ||
def __init__(self, key: str, plural: str, label: str, doc: str, *args: Any) -> None: | ||
... | ||
|
||
def set_tax_benefit_system(self, tax_benefit_system: TaxBenefitSystem) -> None: | ||
self._tax_benefit_system = tax_benefit_system | ||
|
||
def get_variable( | ||
self, | ||
variable_name: str, | ||
check_existence: bool = False, | ||
) -> Variable | None: | ||
return self._tax_benefit_system.get_variable(variable_name, check_existence) | ||
|
||
def check_variable_defined_for_entity(self, variable_name: str) -> None: | ||
variable: Variable | None | ||
entity: Entity | ||
|
||
variable = self.get_variable(variable_name, check_existence=True) | ||
|
||
if variable is not None: | ||
entity = variable.entity | ||
|
||
if entity.key != self.key: | ||
message = ( | ||
f"You tried to compute the variable '{variable_name}' for", | ||
f"the entity '{self.plural}'; however the variable", | ||
f"'{variable_name}' is defined for '{entity.plural}'.", | ||
"Learn more about entities in our documentation:", | ||
"<https://openfisca.org/doc/coding-the-legislation/50_entities.html>.", | ||
) | ||
raise ValueError(os.linesep.join(message)) | ||
|
||
def check_role_validity(self, role: Any) -> None: | ||
if role is not None and not isinstance(role, Role): | ||
raise ValueError(f"{role} is not a valid role") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,30 @@ | ||
from typing import Protocol | ||
from __future__ import annotations | ||
|
||
from collections.abc import Iterable | ||
from typing import Protocol, TypedDict | ||
|
||
|
||
class Entity(Protocol): | ||
... | ||
|
||
|
||
class GroupEntity(Protocol): | ||
... | ||
|
||
|
||
class Role(Protocol): | ||
max: int | None | ||
subroles: Iterable[Role] | None | ||
|
||
@property | ||
def key(self) -> str: | ||
... | ||
|
||
|
||
class RoleParams(TypedDict, total=False): | ||
key: str | ||
plural: str | ||
label: str | ||
doc: str | ||
max: int | ||
subroles: list[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.