Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107276 > unrolled thread

Re: [Python-ideas] Changing the meaning of bool.__invert__

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2016-04-18 14:41 -0600
Last post2016-04-18 14:41 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [Python-ideas] Changing the meaning of bool.__invert__ Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-18 14:41 -0600

#107276 — Re: [Python-ideas] Changing the meaning of bool.__invert__

FromIan Kelly <ian.g.kelly@gmail.com>
Date2016-04-18 14:41 -0600
SubjectRe: [Python-ideas] Changing the meaning of bool.__invert__
Message-ID<mailman.156.1461012147.6324.python-list@python.org>
On Sun, Apr 17, 2016 at 12:24 PM, Pavol Lisy <pavol.lisy@gmail.com> wrote:
> 2016-04-09 17:43 GMT+02:00, Steven D'Aprano <steve@pearwood.info>:
>> flag ^ flag is useful since we don't have a boolean-xor operator and
>> bitwise-xor does the right thing for bools. And I suppose some people
>> might prefer & and | over boolean-and and boolean-or because they're
>> shorter and require less typing. I don't think that's a particularly
>> good reason for using them, and as you say, you do have to guard
>> against non-bools slipping, but Consenting Adults applies.
>
> They are also useful if you need to avoid short-circuit evaluation.

One can easily write functions to do that.

    def long_or(a, b):
        """Equivalent to a or b but always evaluates both expressions."""
        return a or b

long_or(a, b) may not be as pretty as a | b, but I'll argue that it's
more readable since it's up-front about its intent, whereas a | b
looks like it could just be a mistake.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web