[Python-ideas] Changing all() and any() to take multiple arguments

Clay Sweetser clay.sweetser at gmail.com
Mon Aug 26 09:28:14 CEST 2013


On Aug 26, 2013 3:24 AM, "Chris Angelico" <rosuav at gmail.com> wrote:
>
> On Mon, Aug 26, 2013 at 2:50 PM, Clay Sweetser <clay.sweetser at gmail.com>
wrote:
> > Meaning either that one must write either this, and use parenthesis to
avoid
> > some obscure order of operations error:
> >     def is_enabled(self):
> >         return (
> >             (self.connected) and
> >             (not self.broadcasting) and
> >             (self.mode is 'client')
> >         )
>
> I'd be inclined toward this option, especially if some of your
> expressions are complex checks - the 'and' will short-circuit, a tuple
> won't. It looks perfectly readable, to me. Side point: I'd be cautious
> about using 'is' with strings, unless you have some way of
> guaranteeing that both sides have been interned.
Heh, I had actually changed that snippet somewhat from its original source.
My own code uses many constants, so it's something like "MODE is
CLIENT_TO_CLIENT" (The way commands in sublime text are written makes it
almost mandatory to use globals in order to share state).
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130826/fd4ac1d7/attachment.html>


More information about the Python-ideas mailing list