<br><br><div class="gmail_quote">On Mon, Jun 6, 2011 at 23:57, Georg Brandl <span dir="ltr"><<a href="mailto:g.brandl@gmx.net">g.brandl@gmx.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 06/07/11 05:20, brett.cannon wrote:<br>
> <a href="http://hg.python.org/cpython/rev/fc282e375703" target="_blank">http://hg.python.org/cpython/rev/fc282e375703</a><br>
> changeset: 70695:fc282e375703<br>
> user: Brett Cannon <<a href="mailto:brett@python.org">brett@python.org</a>><br>
> date: Mon Jun 06 20:20:36 2011 -0700<br>
> summary:<br>
> Remove some extraneous parentheses and swap the comparison order to<br>
> prevent accidental assignment.<br>
><br>
> Silences a warning from LLVM/clang 2.9.<br>
<br>
</div>Swapping the comparison order here seems a bit inconsistent to me. There are<br>
lots of others around (e.g. "len == 0" in the patch context below). Why is<br>
this one so special?<br>
<br></blockquote><div><br></div><div>Old habit on how to do comparisons in C. Because C treats assignment as an expression it means comparisons can accidentally become an assignment if you accidentally leave out an = sign. By reversing this order it is simply not possible to have that silent bug and instead you would get a compiler error about trying to assign to a constant.</div>
<div><br></div><div>I'll revert that part of the change.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I think that another developer even got told off once for these kinds of<br>
comparisons.<br>
<br>
I hope the Clang warning is only about the parentheses.<br></blockquote><div><br></div><div>Yes, Clang only warned about the parentheses.</div><div><br></div><div>-Brett</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Georg<br>
<div class="im"><br>
> files:<br>
> Modules/arraymodule.c | 2 +-<br>
> 1 files changed, 1 insertions(+), 1 deletions(-)<br>
><br>
><br>
> diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c<br>
> --- a/Modules/arraymodule.c<br>
> +++ b/Modules/arraymodule.c<br>
> @@ -2091,7 +2091,7 @@<br>
> if (len == 0) {<br>
> return PyUnicode_FromFormat("array('%c')", (int)typecode);<br>
> }<br>
> - if ((typecode == 'u'))<br>
> + if ('u' == typecode)<br>
> v = array_tounicode(a, NULL);<br>
> else<br>
> v = array_tolist(a, NULL);<br>
<br>
<br>
<br>
</div>_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/brett%40python.org" target="_blank">http://mail.python.org/mailman/options/python-dev/brett%40python.org</a><br>
</blockquote></div><br>