From 5fb6fa38aae95d8540124016a8b9a9aa544b076e Mon Sep 17 00:00:00 2001 From: gcarq Date: Sat, 24 Mar 2018 23:32:17 +0100 Subject: [PATCH] apply __slots__ to resolver and reintroduce type conversations --- freqtrade/strategy/resolver.py | 21 +++++++++++---------- freqtrade/tests/strategy/test_strategy.py | 1 - 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/freqtrade/strategy/resolver.py b/freqtrade/strategy/resolver.py index d5e9e7b5c..18a03ea58 100644 --- a/freqtrade/strategy/resolver.py +++ b/freqtrade/strategy/resolver.py @@ -21,6 +21,9 @@ class StrategyResolver(object): """ This class contains all the logic to load custom strategy class """ + + __slots__ = ['strategy'] + def __init__(self, config: Optional[Dict] = None) -> None: """ Load the custom class from config parameter @@ -39,22 +42,24 @@ class StrategyResolver(object): logger.info("Override strategy \'minimal_roi\' with value in config file.") if 'stoploss' in config: - self.strategy.stoploss = float(config['stoploss']) + self.strategy.stoploss = config['stoploss'] logger.info( "Override strategy \'stoploss\' with value in config file: %s.", config['stoploss'] ) if 'ticker_interval' in config: - self.strategy.ticker_interval = int(config['ticker_interval']) + self.strategy.ticker_interval = config['ticker_interval'] logger.info( "Override strategy \'ticker_interval\' with value in config file: %s.", config['ticker_interval'] ) - # Minimal ROI designed for the strategy + # Sort and apply type conversions self.strategy.minimal_roi = OrderedDict(sorted( {int(key): value for (key, value) in self.strategy.minimal_roi.items()}.items(), - key=lambda t: t[0])) # sort after converting to number + key=lambda t: t[0])) + self.strategy.stoploss = float(self.strategy.stoploss) + self.strategy.ticker_interval = int(self.strategy.ticker_interval) def _load_strategy(self, strategy_name: str) -> Optional[IStrategy]: """ @@ -76,16 +81,12 @@ class StrategyResolver(object): raise ImportError('not found') # Fallback to the default strategy - except (ImportError, TypeError) as error: - logger.error( + except (ImportError, TypeError): + logger.exception( "Impossible to load Strategy '%s'. This class does not exist" " or contains Python code errors", strategy_name ) - logger.error( - "The error is:\n%s.", - error - ) return None @staticmethod diff --git a/freqtrade/tests/strategy/test_strategy.py b/freqtrade/tests/strategy/test_strategy.py index 6e69e2b09..87818b05f 100644 --- a/freqtrade/tests/strategy/test_strategy.py +++ b/freqtrade/tests/strategy/test_strategy.py @@ -115,7 +115,6 @@ def test_strategy_override_ticker_interval(caplog): def test_strategy_fallback_default_strategy(): strategy = StrategyResolver() - strategy.logger = logging.getLogger(__name__) assert not hasattr(StrategyResolver, 'custom_strategy') strategy._load_strategy('../../super_duper')