From 350fcc071e07952e50a518f27b79de6b387cab19 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 26 Sep 2020 16:33:48 +0200 Subject: [PATCH] Don't use __code__ __code__ is a special method name used by python already source: https://docs.python.org/3/reference/datamodel.html#special-method-names --- freqtrade/resolvers/iresolver.py | 2 +- freqtrade/rpc/api_server.py | 2 +- tests/strategy/test_strategy.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/freqtrade/resolvers/iresolver.py b/freqtrade/resolvers/iresolver.py index 801ad956b..9c3a33f2b 100644 --- a/freqtrade/resolvers/iresolver.py +++ b/freqtrade/resolvers/iresolver.py @@ -98,7 +98,7 @@ class IResolver: if obj: obj[0].__file__ = str(entry) if add_source: - obj[0].__code__ = obj[1] + obj[0].__source__ = obj[1] return (obj[0], module_path) return (None, None) diff --git a/freqtrade/rpc/api_server.py b/freqtrade/rpc/api_server.py index 489b8760a..ea616c0ec 100644 --- a/freqtrade/rpc/api_server.py +++ b/freqtrade/rpc/api_server.py @@ -608,7 +608,7 @@ class ApiServer(RPC): return self.rest_dump({ 'strategy': strategy_obj.get_strategy_name(), - 'code': strategy_obj.__code__, + 'code': strategy_obj.__source__, }) @require_login diff --git a/tests/strategy/test_strategy.py b/tests/strategy/test_strategy.py index 1641098e9..1c692d2da 100644 --- a/tests/strategy/test_strategy.py +++ b/tests/strategy/test_strategy.py @@ -55,8 +55,8 @@ def test_load_strategy(default_conf, result): 'strategy_path': str(Path(__file__).parents[2] / 'freqtrade/templates') }) strategy = StrategyResolver.load_strategy(default_conf) - assert isinstance(strategy.__code__, str) - assert 'class SampleStrategy' in strategy.__code__ + assert isinstance(strategy.__source__, str) + assert 'class SampleStrategy' in strategy.__source__ assert isinstance(strategy.__file__, str) assert 'rsi' in strategy.advise_indicators(result, {'pair': 'ETH/BTC'})