diff --git a/freqtrade/strategy/hyper.py b/freqtrade/strategy/hyper.py index b8bfef767..461e6314f 100644 --- a/freqtrade/strategy/hyper.py +++ b/freqtrade/strategy/hyper.py @@ -3,6 +3,7 @@ IHyperStrategy interface, hyperoptable Parameter class. This module defines a base class for auto-hyperoptable strategies. """ import logging +from abc import ABC, abstractmethod from contextlib import suppress from typing import Any, Iterator, Optional, Sequence, Tuple, Union @@ -16,7 +17,7 @@ from freqtrade.exceptions import OperationalException logger = logging.getLogger(__name__) -class BaseParameter(object): +class BaseParameter(ABC): """ Defines a parameter that can be optimized by hyperopt. """ @@ -46,8 +47,11 @@ class BaseParameter(object): def __repr__(self): return f'{self.__class__.__name__}({self.value})' + @abstractmethod def get_space(self, name: str) -> Union['Integer', 'Real', 'Categorical']: - raise NotImplementedError() + """ + Get-space - will be used by Hyperopt to get the hyperopt Space + """ class IntParameter(BaseParameter): diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index 5dd459238..e9d57dd17 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -571,9 +571,8 @@ def test_hyperopt_parameters(): with pytest.raises(OperationalException, match=r"FloatParameter space invalid\."): FloatParameter([0, 10], high=7, default=5, space='buy') - x = BaseParameter(opt_range=[0, 1], default=1, space='buy') - with pytest.raises(NotImplementedError): - x.get_space('space') + with pytest.raises(TypeError): + BaseParameter(opt_range=[0, 1], default=1, space='buy') fltpar = IntParameter(low=0, high=5, default=1, space='buy') assert fltpar.value == 1