-
Notifications
You must be signed in to change notification settings - Fork 16
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
Improvements on scenario.py get_survey_scenario.py #158
Conversation
80dc50e
to
057a98e
Compare
4330b6f
to
8d50ba4
Compare
survey_scenario.init_from_data( | ||
data = data, | ||
rebuild_input_data = rebuild_input_data, | ||
) | ||
return survey_scenario | ||
|
||
|
||
@dispatch(TaxBenefitSystem, Reform) # type: ignore |
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.
Id do not know this decorator and it is not straightforward to understand what it does. Could you provide some ref.
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.
There is a lot of complexity checking whether a value is present or None
, or if it has a certain type, and that implies a lot of if
and is bug prone.
What this does is to validate data : depending on the value of the argument used, it'll dispatch to a version of the function that handles that specific case.
What we do is to be sure to dispatch to the expected behaviour by type checking the arguments.
Usually you don't need this, but I think for this repo it'll help us catch several bugs and reduce code complexity with little change.
We'll be able to factor out several branch conditions without risk.
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.
I can add a comment in the code for other readers as well if that helps.
f8f60fa
to
aa0c0af
Compare
aa0c0af
to
ffb9681
Compare
Changes
scenario.py
andget_survey_scenario.py
get_survey_scenario.py
multipledispatch
to reduce code complexitySplit unit and integration tests
The idea of this separation is to have, in one hand, integration tests like calculating income tax.
And, on the other, tests that only test certain functions in isolation.
This is practical as:
metier
point of viewUse
multipledispatch
to reduce code complexityThis module contains a lot of conditional branching, and that's bug prone and makes difficult to encapsulate functionality.
For example, if we want to add conditions by
millésime
, we end up with a lot ofif
s that render the code extremely hard to maintain.With dynamic dispatch, we can do so in a cleaner way.
This is closely similar to OpenFisca's
formulas
, although simpler, generic, and more performant.