[Python-Dev] cpython: Remove some extraneous parentheses and swap the comparison order to (original) (raw)
Brett Cannon brett at python.org
Wed Jun 8 05:07:49 CEST 2011
- Previous message: [Python-Dev] cpython: Remove some extraneous parentheses and swap the comparison order to
- Next message: [Python-Dev] [Python-checkins] cpython: Issue #12040: Expose a new attribute `sentinel` on instances of
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Jun 6, 2011 at 23:57, Georg Brandl <g.brandl at gmx.net> wrote:
On 06/07/11 05:20, brett.cannon wrote: > http://hg.python.org/cpython/rev/fc282e375703 > changeset: 70695:fc282e375703 > user: Brett Cannon <brett at python.org> > date: Mon Jun 06 20:20:36 2011 -0700 > summary: > Remove some extraneous parentheses and swap the comparison order to > prevent accidental assignment. > > Silences a warning from LLVM/clang 2.9.
Swapping the comparison order here seems a bit inconsistent to me. There are lots of others around (e.g. "len == 0" in the patch context below). Why is this one so special? 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.
I'll revert that part of the change.
I think that another developer even got told off once for these kinds of comparisons.
I hope the Clang warning is only about the parentheses.
Yes, Clang only warned about the parentheses.
-Brett
Georg > files: > Modules/arraymodule.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > > diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c > --- a/Modules/arraymodule.c > +++ b/Modules/arraymodule.c > @@ -2091,7 +2091,7 @@ > if (len == 0) { > return PyUnicodeFromFormat("array('%c')", (int)typecode); > } > - if ((typecode == 'u')) > + if ('u' == typecode) > v = arraytounicode(a, NULL); > else > v = arraytolist(a, NULL);
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/brett%40python.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20110607/475d2f66/attachment.html>
- Previous message: [Python-Dev] cpython: Remove some extraneous parentheses and swap the comparison order to
- Next message: [Python-Dev] [Python-checkins] cpython: Issue #12040: Expose a new attribute `sentinel` on instances of
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]