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

Signed-off-by: Claudio Bley <cbley@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(-) diff --git a/python/generator.py b/python/generator.py index 427cebc..10390c3 100755 --- a/python/generator.py +++ b/python/generator.py @@ -1455,8 +1455,7 @@ def buildWrappers(module): elif classname in [ "virDomainSnapshot" ]: classes.write(" self._dom = dom\n") classes.write(" self._conn = dom.connect()\n") - classes.write(" if _obj != None:self._o = _obj;return\n") - classes.write(" self._o = None\n\n") + classes.write(" self._o = _obj\n\n") destruct=None if classes_destructors.has_key(classname): classes.write(" def __del__(self):\n") -- 1.7.9.5

On 08/21/2013 08:05 AM, Claudio Bley wrote:
Signed-off-by: Claudio Bley <cbley@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.
diff --git a/python/generator.py b/python/generator.py index 427cebc..10390c3 100755 --- a/python/generator.py +++ b/python/generator.py @@ -1455,8 +1455,7 @@ def buildWrappers(module): elif classname in [ "virDomainSnapshot" ]: classes.write(" self._dom = dom\n") classes.write(" self._conn = dom.connect()\n") - classes.write(" if _obj != None:self._o = _obj;return\n") - classes.write(" self._o = None\n\n") + classes.write(" self._o = _obj\n\n") destruct=None if classes_destructors.has_key(classname): classes.write(" def __del__(self):\n")
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

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@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

At Thu, 22 Aug 2013 09:55:08 +0200, Claudio Bley wrote:
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@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.
Pushed now. 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
participants (2)
-
Claudio Bley
-
Eric Blake