Improve if formatting

This commit is contained in:
Matthias 2023-01-02 08:44:00 +01:00
parent e89609dc3a
commit a712c5d42c

View File

@ -184,9 +184,11 @@ class NameUpdater(ast.NodeTransformer):
def visit_Attribute(self, node): def visit_Attribute(self, node):
# if the attribute name is 'nr_of_successful_buys', # if the attribute name is 'nr_of_successful_buys',
# update it to 'nr_of_successful_entries' # update it to 'nr_of_successful_entries'
if isinstance(node.value, ast.Name) and \ if (
node.value.id == 'trades' and \ isinstance(node.value, ast.Name)
node.attr == 'nr_of_successful_buys': and node.value.id == 'trades'
and node.attr == 'nr_of_successful_buys'
):
node.attr = 'nr_of_successful_entries' node.attr = 'nr_of_successful_entries'
return self.generic_visit(node) return self.generic_visit(node)
@ -208,9 +210,11 @@ class NameUpdater(ast.NodeTransformer):
# otherwise, update its value to 3 # otherwise, update its value to 3
else: else:
for child in node.body: for child in node.body:
if isinstance(child, ast.Assign) and \ if (
isinstance(child.targets[0], ast.Name) and \ isinstance(child, ast.Assign)
child.targets[0].id == 'INTERFACE_VERSION': and isinstance(child.targets[0], ast.Name)
and child.targets[0].id == 'INTERFACE_VERSION'
):
child.value = ast.parse('3').body[0].value child.value = ast.parse('3').body[0].value
return self.generic_visit(node) return self.generic_visit(node)
@ -253,8 +257,6 @@ class NameUpdater(ast.NodeTransformer):
def visit_Constant(self, node): def visit_Constant(self, node):
# do not update the names in import statements # do not update the names in import statements
if node.value in \ if node.value in StrategyUpdater.otif_ot_unfilledtimeout:
StrategyUpdater.otif_ot_unfilledtimeout: node.value = StrategyUpdater.otif_ot_unfilledtimeout[node.value]
node.value = \
StrategyUpdater.otif_ot_unfilledtimeout[node.value]
return node return node