-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve usability of Enum values #840
Conversation
7fd095f
to
d60052f
Compare
6c2272c
to
b0e15b0
Compare
Might be tested with this code calling
|
@sandcha That looks like it would work, and OpenFisca Tunisia needs to be updated to Core 25 first. |
b0e15b0
to
f000f22
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Morendil!
It resolves the initial issue on openfisca-tunisia
.
# However, variables (and hence their possible_values) are loaded by a call to load_module, | ||
# which gives them a different identity from the ones imported in the usual way. | ||
# So, instead of relying on the "cls" passed in, we use only its name to check that | ||
# the values in the array, if non-empty, are of the right type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shorten comment or keep in PR only?
# the values in the array, if non-empty, are of the right type. | |
# "cls" generally comes from variables.possible_values (thus, from load_module) | |
# while the array values may come from directly importing a module containing an Enum class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you know I'm not a fan of long comments in code, even of comments in general. In this particular case I really feel that the somewhat long explanation is needed to make sense of the code that follows…
@@ -141,6 +141,8 @@ def calculate(self, variable_name, period, **parameters): | |||
if array is None: | |||
array = holder.default_array() | |||
|
|||
array = self._cast_formula_result(array, variable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Allow the use of Enum values in comparisons, working around our abuse of the Python module system for TaxBenefitSystem loading.
Tested by updating
test_holders.py
to import HousingOccupancyStatus instead of gettingpossible_values
. (Also tested, outside of CI, against the YAML test in this branch of France.)