From c091426c442974d80e32ba1066fe57fc2871ca1a Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 4 Nov 2025 06:54:42 +0100 Subject: [PATCH] feat: improve Auto-space detection logic --- freqtrade/strategy/hyper.py | 26 ++++++++++++++------------ tests/strategy/test_interface.py | 9 ++++++++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/freqtrade/strategy/hyper.py b/freqtrade/strategy/hyper.py index 5bf1c49a2..847aac102 100644 --- a/freqtrade/strategy/hyper.py +++ b/freqtrade/strategy/hyper.py @@ -174,21 +174,23 @@ def detect_all_parameters( attr = getattr(obj, attr_name) if not issubclass(attr.__class__, BaseParameter): continue - category = attr.category - if attr.category is None: - # Category auto detection - for category in auto_categories: - if category == attr.category or ( - attr_name.startswith(category + "_") and attr.category is None - ): - attr.category = category - if attr.category is None or ( - attr_name.startswith(category + "_") + auto_category: str | None = None + # Category auto detection + for category in auto_categories: + if attr_name.startswith(category + "_"): + auto_category = category + break + if auto_category is None and attr.category is None: + raise OperationalException(f"Cannot determine parameter space for {attr_name}.") + if auto_category is not None and attr.category is None: + attr.category = auto_category + if ( + auto_category is not None and attr.category is not None - and attr.category != category + and auto_category != attr.category ): raise OperationalException( - f"Inconclusive parameter name {attr_name}, space: {attr.category}." + f"Conflicting parameter space for {attr_name}: {auto_category} vs {attr.category}." ) attr.name = attr_name result[attr.category][attr_name] = attr diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index a8e32ca54..324617869 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -951,7 +951,14 @@ def test_auto_hyperopt_interface(default_conf): strategy.__class__.sell_rsi = IntParameter([0, 10], default=5, space="buy") - with pytest.raises(OperationalException, match=r"Inconclusive parameter.*"): + with pytest.raises(OperationalException, match=r"Conflicting parameter space.*"): + detect_all_parameters(strategy.__class__) + + strategy.__class__.exit22_rsi = IntParameter([0, 10], default=5) + + with pytest.raises( + OperationalException, match=r"Cannot determine parameter space for exit22_rsi\." + ): detect_all_parameters(strategy.__class__)