Fix mutable defaults, enable bugbear ruff rule #10173
Open
+25
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Mutable defaults are dangerous - as they can lead to state leaking around.
Quick changelog
todo
DataKitchen.use_strategy_to_populate_indicators()
defaults@robcaulk I'd apreciate your help in fixing
use_strategy_to_populate_indicators()
.While it seems simple at first (simply remove the default dicts) - it's actually not - as there's several usages without these arguments - and i'm afraid that it's implicitly relying on the cache these (now global) dictionaries provide.
For all calls without the
corr_dataframes
andbase_dataframes
arguments these 2 variables become "global state", independent of theDataKitchen
instance they're actually used in.As a consequence, this state could "leak around" across individual DataKitchens (across individual Pairs) - leading to very subtle, almost impossible to debug bugs.
a very simple demonstration of this:
Now a simple fix could be to simply make them mandatory, providing empty dictionaries where the arguments are currently missing.
my fear however is that freqAI is (implicitly) relying on this global, shared state - and simply removing their "Optionality" will break things...