Skip to content

Commit

Permalink
Modified CondExprNode generate_evaluation_code to resolve cythongh-5555
Browse files Browse the repository at this point in the history
Only wrap conditional statement in parenthesis if it does not start
with ( or does not end with ) already.
  • Loading branch information
oleksandr-pavlyk committed Aug 2, 2023
1 parent b4671ba commit 5654c4d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Cython/Compiler/ExprNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12861,7 +12861,10 @@ def generate_evaluation_code(self, code):
code.mark_pos(self.pos)
self.allocate_temp_result(code)
self.test.generate_evaluation_code(code)
code.putln("if (%s) {" % self.test.result())
cond_val = self.test.result()
if not cond_val.startswith("(") or not cond_val.endswith(")"):
cond_val = "(" + cond_val + ")"
code.putln("if %s {" % cond_val)
self.eval_and_get(code, self.true_val)
code.putln("} else {")
self.eval_and_get(code, self.false_val)
Expand Down

0 comments on commit 5654c4d

Please sign in to comment.