Skip to content

Commit

Permalink
Add back type check on variable entity
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagnoux authored and Morendil committed Apr 11, 2019
1 parent d798770 commit 55f7f4d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions openfisca_core/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from datetime import date

from openfisca_core import periods
from openfisca_core.entities import Entity
from openfisca_core.indexed_enums import Enum, EnumArray, ENUM_ARRAY_DTYPE
from openfisca_core.periods import DAY, MONTH, YEAR, ETERNITY
from openfisca_core.tools import eval_expression
Expand Down Expand Up @@ -210,11 +211,8 @@ def set(self, attributes, attribute_name, required = False, allowed_values = Non
return value

def set_entity(self, entity):
# TODO - isinstance() won't work due to use of load_module to load tax_benefit_system
# Just trust the input in the meantime
# if not isinstance(entity, entities.Entity):
# raise ValueError("Invalid value '{}' for attribute 'entity' in variable '{}'. Must be an instance of Entity."
# .format(entity, self.name).encode('utf-8'))
if not isinstance(entity, Entity):
raise ValueError(f"Invalid value '{entity}' for attribute 'entity' in variable '{self.name}'. Must be an instance of Entity.")
return entity

def set_possible_values(self, possible_values):
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_simulation_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def int_variable(persons):
class intvar(Variable):
definition_period = ETERNITY
value_type = int
entity = persons.__class__
entity = persons

def __init__(self):
super().__init__()
Expand All @@ -57,7 +57,7 @@ def date_variable(persons):
class datevar(Variable):
definition_period = ETERNITY
value_type = date
entity = persons.__class__
entity = persons

def __init__(self):
super().__init__()
Expand Down

0 comments on commit 55f7f4d

Please sign in to comment.