Metaprogramming Example

Paul McGuire ptmcg at austin.rr.com
Thu Apr 17 09:05:54 EDT 2008


On Apr 17, 7:25 am, andrew cooke <and... at acooke.org> wrote:
> On Apr 17, 7:12 am, "bruno.desthuilli... at gmail.com"<bruno.desthuilli... at gmail.com> wrote:
>
> One other question.  I had "foo is False" and you said I need
> equality, which is a good point.  However, in any other language "not
> foo" would be preferable.  I was surprised you didn't suggest that
> (and I'm unsure now why I didn't write it that way myself).  Is there
> some common Python standard that prefers "foo == False" to "not foo"?
>
In addition to the problematic "foo is False" test, Bruno was also
saying that assertions of True tend to be more readable than negated
assertions of False.

In your original, you were testing for not P or not Q, Bruno recoded
this to the equivalent not(P and Q).  That is, the direct way to
change the 'is' identity testing to equality testing would have been:

    if (not self.ignore_identical or
        new_value != obj._auto_write_dict[self.name]):

But Bruno further changed this to:

    if not (self.ignore_identical and
        new_value == obj._auto_write_dict[self.name]):


-- Paul



More information about the Python-list mailing list