openfisca / openfisca-core

OpenFisca core engine. See other repositories for countries-specific code & data.
https://openfisca.org
GNU Affero General Public License v3.0
170 stars 75 forks source link

Detect duplicate calls of method modify_parameters #1278

Open eraviart opened 1 month ago

eraviart commented 1 month ago

When method Reform.modify_parameters is called twice, the second call resets the changes made by the first call. It is not a bug, but it can cause hard to debug errors.

For example, this bug occurred here.

It would be nice if a warning was added when method modify_parameters is called more than once.

bonjourmauko commented 1 month ago

Hi @eraviart ! I'm not very familiar with that method. Should it allow for commutative modifications at all?

I see the code modifies the global state, maybe we can pass around a State monad, or a list, to keep track of the changes:

def modify_parameters(fun: ParamSpec, ctx: Sequence[ParameterNode]) -> Sequence[ParameterNode]:
    # ...
    return [new_node, *ctx]