[libvirt] [PATCH] python: simplify complicated conditional assignment

Claudio Bley cbley at av-test.de
Thu Aug 22 07:55:08 UTC 2013


At Wed, 21 Aug 2013 10:24:16 -0600,
Eric Blake wrote:
> 
> On 08/21/2013 08:05 AM, Claudio Bley wrote:
> > 
> > Signed-off-by: Claudio Bley <cbley at av-test.de>
> > ---
> > Just noticed this while reading the generated .py files.
> > 
> > Might save a few cycles eventually...
> > 
> >  python/generator.py |    3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> ACK.

Thanks.

But, I was still thinking about a possible case where doing the
assignment in this way was necessary or useful.

In the case if someone actually overwrites the __ne__ operator
of a class in some strange way:

def __ne__(self, other):
  if other is None:
    return False
  else:
    return NotImplemented

(and __eq__ likewise), such that the instance would compare equal to
None, the semantic of the codes would differ.

IMO, we don't need to care if someone chooses to implement such
awkward equality rules. In the end, (s)he could directly pass None as
an argument if None is what is inteded. So, I'm going to push this if
nobody objects in the next few hours.

Furthermore, one should not compare to None using the equality
operators anyways, as recommended by PEP 8. Next patch coming up...

/ Claudio
-- 
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:<http://www.av-test.org>

Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern




More information about the libvir-list mailing list