Skip to content

Commit 584e97f

Browse files
committed
doc(types): add projector types
1 parent 4e3dfcb commit 584e97f

File tree

5 files changed

+20
-29
lines changed

5 files changed

+20
-29
lines changed

openfisca_core/projectors/entity_to_person_projector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class EntityToPersonProjector(Projector):
55
"""For instance person.family."""
66

7-
def __init__(self, entity, parent=None):
7+
def __init__(self, entity, parent=None) -> None:
88
self.reference_entity = entity
99
self.parent = parent
1010

openfisca_core/projectors/first_person_to_entity_projector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class FirstPersonToEntityProjector(Projector):
55
"""For instance famille.first_person."""
66

7-
def __init__(self, entity, parent=None):
7+
def __init__(self, entity, parent=None) -> None:
88
self.target_entity = entity
99
self.reference_entity = entity.members
1010
self.parent = parent

openfisca_core/projectors/helpers.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from openfisca_core import entities, projectors
66

7-
from .types import GroupEntity, GroupPopulation, Role, SingleEntity, SinglePopulation
7+
from . import types as t
88

99

1010
def projectable(function):
@@ -17,10 +17,10 @@ def projectable(function):
1717

1818

1919
def get_projector_from_shortcut(
20-
population: SinglePopulation | GroupPopulation,
20+
population: t.CorePopulation,
2121
shortcut: str,
22-
parent: projectors.Projector | None = None,
23-
) -> projectors.Projector | None:
22+
parent: t.Projector | None = None,
23+
) -> t.Projector | None:
2424
"""Get a projector from a shortcut.
2525
2626
Projectors are used to project an invidividual Population's or a
@@ -108,12 +108,10 @@ def get_projector_from_shortcut(
108108
109109
"""
110110

111-
entity: SingleEntity | GroupEntity = population.entity
111+
entity: t.CoreEntity = population.entity
112112

113113
if isinstance(entity, entities.Entity):
114-
populations: Mapping[
115-
str, SinglePopulation | GroupPopulation
116-
] = population.simulation.populations
114+
populations: Mapping[str, t.CorePopulation] = population.simulation.populations
117115

118116
if shortcut not in populations.keys():
119117
return None
@@ -124,8 +122,8 @@ def get_projector_from_shortcut(
124122
return projectors.FirstPersonToEntityProjector(population, parent)
125123

126124
if isinstance(entity, entities.GroupEntity):
127-
roles: Iterable[Role] = entity.roles
128-
role: Role | None = entities.find_role(roles, shortcut, total=1)
125+
roles: Iterable[t.Role] = entity.roles
126+
role: t.Role | None = entities.find_role(roles, shortcut, total=1)
129127

130128
if role is not None:
131129
return projectors.UniqueRoleToEntityProjector(population, role, parent)

openfisca_core/projectors/types.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,27 @@
88
# Entities
99

1010

11-
class SingleEntity(t.SingleEntity, Protocol):
12-
...
13-
14-
15-
class GroupEntity(t.GroupEntity, Protocol):
11+
class CoreEntity(t.CoreEntity, Protocol):
1612
...
1713

1814

1915
class Role(t.Role, Protocol):
2016
...
2117

2218

23-
# Populations
19+
# Projectors
2420

2521

26-
class SinglePopulation(t.SinglePopulation, Protocol):
27-
@property
28-
def entity(self) -> t.SingleEntity:
29-
...
22+
class Projector(Protocol):
23+
...
3024

31-
@property
32-
def simulation(self) -> Simulation:
33-
...
25+
26+
# Populations
3427

3528

36-
class GroupPopulation(t.GroupPopulation, Protocol):
29+
class CorePopulation(t.CorePopulation, Protocol):
3730
@property
38-
def entity(self) -> t.GroupEntity:
31+
def entity(self) -> CoreEntity:
3932
...
4033

4134
@property
@@ -48,5 +41,5 @@ def simulation(self) -> Simulation:
4841

4942
class Simulation(t.Simulation, Protocol):
5043
@property
51-
def populations(self) -> Mapping[str, SinglePopulation | GroupPopulation]:
44+
def populations(self) -> Mapping[str, CorePopulation]:
5245
...

openfisca_core/projectors/unique_role_to_entity_projector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class UniqueRoleToEntityProjector(Projector):
55
"""For instance famille.declarant_principal."""
66

7-
def __init__(self, entity, role, parent=None):
7+
def __init__(self, entity, role, parent=None) -> None:
88
self.target_entity = entity
99
self.reference_entity = entity.members
1010
self.parent = parent

0 commit comments

Comments
 (0)