Skip to content

Commit

Permalink
Merge pull request #466 from douglasjacobsen/fix_removed_spaces
Browse files Browse the repository at this point in the history
Revert "Allow expander to return string representation of invalid operators"
  • Loading branch information
rfbgo authored Apr 17, 2024
2 parents e4a2290 + f0f33ea commit aabef3e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
11 changes: 1 addition & 10 deletions lib/ramble/ramble/expander.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@
ast.And: operator.and_, ast.Or: operator.or_, ast.Mod: operator.mod
}

op_str_map = {
operator.add: '+', operator.sub: '-',
operator.mul: '*', operator.truediv: '/',
operator.pow: '**', operator.xor: '^', operator.neg: '-',
operator.gt: '>',
operator.ge: '>=', operator.lt: '<', operator.le: '<=',
operator.and_: 'and', operator.or_: 'or', operator.mod: '%'
}

supported_scalar_function_pointers = {
'str': str,
'int': int,
Expand Down Expand Up @@ -783,7 +774,7 @@ def _eval_binary_ops(self, node):
right_eval = self.eval_math(node.right)
op = supported_math_operators[type(node.op)]
if isinstance(left_eval, six.string_types) or isinstance(right_eval, six.string_types):
return f'{left_eval}{op_str_map[op]}{right_eval}'
raise SyntaxError('Unsupported operand type in binary operator')
return op(left_eval, right_eval)
except TypeError:
raise SyntaxError('Unsupported operand type in binary operator')
Expand Down
4 changes: 1 addition & 3 deletions lib/ramble/ramble/test/expander.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def exp_dict():
('{n_nodes}*{processes_per_node}', '4', set(), 1),
('2**4', '16', set(), 1),
('{((((16-10+2)/4)**2)*4)}', '16.0', set(), 1),
('"gromacs +blas"', 'gromacs +blas', set(), 1),
('gromacs +blas', 'gromacs+blas', set(), 1),
('gromacs +blas', 'gromacs +blas', set(), 1),
('range(0, 5)', '[0, 1, 2, 3, 4]', set(), 1),
('{decimal.06.var}', 'foo', set(), 1),
('{}', '{}', set(), 1),
Expand All @@ -74,7 +73,6 @@ def exp_dict():
('"2.1.1" in ["2.1.1", "3.1.1", "4.2.1"]', 'True', set(), 1),
('"2.1.2" in ["2.1.1", "3.1.1", "4.2.1"]', 'False', set(), 1),
('{test_mask}', '0x0', set(['test_mask']), 1),
('intel-mpi-benchmarks == intel-mpi-benchmarks', 'True', set(), 1),
]
)
def test_expansions(input, output, no_expand_vars, passes):
Expand Down

0 comments on commit aabef3e

Please sign in to comment.