Commit 6a5a9c05 authored by Stefan Behnel's avatar Stefan Behnel

Avoid useless None check when testing non-None containers for emptiness, e.g....

Avoid useless None check when testing non-None containers for emptiness, e.g. for the result of a comprehension.
parent e207f426
...@@ -13041,11 +13041,9 @@ class CoerceToBooleanNode(CoercionNode): ...@@ -13041,11 +13041,9 @@ class CoerceToBooleanNode(CoercionNode):
return return
test_func = self._special_builtins.get(self.arg.type) test_func = self._special_builtins.get(self.arg.type)
if test_func is not None: if test_func is not None:
code.putln("%s = (%s != Py_None) && (%s(%s) != 0);" % ( checks = ["(%s != Py_None)" % self.arg.py_result()] if self.arg.may_be_none() else []
self.result(), checks.append("(%s(%s) != 0)" % (test_func, self.arg.py_result()))
self.arg.py_result(), code.putln("%s = %s;" % (self.result(), '&&'.join(checks)))
test_func,
self.arg.py_result()))
else: else:
code.putln( code.putln(
"%s = __Pyx_PyObject_IsTrue(%s); %s" % ( "%s = __Pyx_PyObject_IsTrue(%s); %s" % (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment