sped up the function generic_visit that now skips unnecessary fields

added mentioning of skipped class names since they could not be found
This commit is contained in:
hippocritical 2022-12-30 21:48:06 +01:00
parent a6356c2821
commit 82218d01f4
2 changed files with 9 additions and 4 deletions

View File

@ -25,11 +25,12 @@ def start_strategy_update(args: Dict[str, Any]) -> None:
config, enum_failed=True, recursive=config.get('recursive_strategy_search', False)) config, enum_failed=True, recursive=config.get('recursive_strategy_search', False))
filtered_strategy_objs = [] filtered_strategy_objs = []
for args_strategy in args['strategy_list']: for strategy_obj in strategy_objs:
for strategy_obj in strategy_objs: for args_strategy in args['strategy_list']:
if strategy_obj['name'] == args_strategy and strategy_obj not in filtered_strategy_objs: if strategy_obj['name'] == args_strategy and strategy_obj not in filtered_strategy_objs:
filtered_strategy_objs.append(strategy_obj) filtered_strategy_objs.append(strategy_obj)
break break
print(f"strategy {strategy_obj['name']} could not be loaded or found and is skipped.")
for filtered_strategy_obj in filtered_strategy_objs: for filtered_strategy_obj in filtered_strategy_objs:
# Initialize backtesting object # Initialize backtesting object

View File

@ -52,6 +52,7 @@ class StrategyUpdater:
""" """
source_file = strategy_obj['location'] source_file = strategy_obj['location']
print(f"started conversion of {source_file}")
strategies_backup_folder = Path.joinpath(config['user_data_dir'], "strategies_orig_updater") strategies_backup_folder = Path.joinpath(config['user_data_dir'], "strategies_orig_updater")
target_file = Path.joinpath(strategies_backup_folder, strategy_obj['location_rel']) target_file = Path.joinpath(strategies_backup_folder, strategy_obj['location_rel'])
@ -106,6 +107,8 @@ class NameUpdater(ast.NodeTransformer):
# traverse the AST recursively by calling the visitor method for each child node # traverse the AST recursively by calling the visitor method for each child node
if hasattr(node, "_fields"): if hasattr(node, "_fields"):
for field_name, field_value in ast.iter_fields(node): for field_name, field_value in ast.iter_fields(node):
if not isinstance(field_value, ast.AST):
continue # to avoid unnecessary loops
self.visit(field_value) self.visit(field_value)
self.generic_visit(field_value) self.generic_visit(field_value)
self.check_fields(field_value) self.check_fields(field_value)
@ -204,8 +207,9 @@ class NameUpdater(ast.NodeTransformer):
node.slice.value = StrategyUpdater.rename_dict[node.slice.value] node.slice.value = StrategyUpdater.rename_dict[node.slice.value]
if hasattr(node.slice, "elts"): if hasattr(node.slice, "elts"):
self.visit_slice_elts(node.slice.elts) self.visit_slice_elts(node.slice.elts)
if hasattr(node.slice.value, "elts"): if hasattr(node.slice, "value"):
self.visit_slice_elts(node.slice.value.elts) if hasattr(node.slice.value, "elts"):
self.visit_slice_elts(node.slice.value.elts)
return node return node
# elts can have elts (technically recursively) # elts can have elts (technically recursively)