From Dan Kenigsberg <danken(a)redhat.com>:
Dan Kenigsberg has uploaded a new change for review.
Change subject: replace dir() with vars() in few places
......................................................................
replace dir() with vars() in few places
In 3 palces in our code, we make an effort to iterate only the variable
of a class, skipping special attributes based on their understcore
prefix. raymondh noted[*] that vars() is often forgotten. And indeed -
we did forget it.
There are 11 other references to dir() in the code, but changing them to
vars() is less obviously needed.
[*]
https://www.youtube.com/watch?v=p33CVV29OG8
Change-Id: I0790b0bc78788e9b418121665e30bbfb48d40be6
Signed-off-by: Dan Kenigsberg <danken(a)redhat.com>
---
M lib/vdsm/libvirtconnection.py
M lib/yajsonrpc/stomp.py
M vdsm/virt/vmdevices/core.py
3 files changed, 7 insertions(+), 8 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/79/68679/1
diff --git a/lib/vdsm/libvirtconnection.py b/lib/vdsm/libvirtconnection.py
index 63d961d..815aff4 100644
--- a/lib/vdsm/libvirtconnection.py
+++ b/lib/vdsm/libvirtconnection.py
@@ -122,9 +122,9 @@
try:
ret = f(*args, **kwargs)
if isinstance(ret, libvirt.virDomain):
- for name in dir(ret):
+ for name in vars(ret):
method = getattr(ret, name)
- if callable(method) and name[0] != '_':
+ if callable(method):
setattr(ret, name,
wrapMethod(utils.weakmethod(method)))
return ret
@@ -164,9 +164,9 @@
__connections[id(target)] = conn
setattr(conn, 'pingLibvirt', getattr(conn, 'getLibVersion'))
- for name in dir(libvirt.virConnect):
+ for name in vars(libvirt.virConnect):
method = getattr(conn, name)
- if callable(method) and name[0] != '_':
+ if callable(method):
setattr(conn, name,
wrapMethod(utils.weakmethod(method)))
if target is not None:
diff --git a/lib/yajsonrpc/stomp.py b/lib/yajsonrpc/stomp.py
index 392a63a..2954c21 100644
--- a/lib/yajsonrpc/stomp.py
+++ b/lib/yajsonrpc/stomp.py
@@ -71,8 +71,7 @@
HEARTEBEAT = "heart-beat"
-COMMANDS = tuple([command for command in dir(Command)
- if not command.startswith('_')])
+COMMANDS = tuple([command for command in vars(Command)])
class AckMode(object):
diff --git a/vdsm/virt/vmdevices/core.py b/vdsm/virt/vmdevices/core.py
index 4066ad7..e6d5738 100644
--- a/vdsm/virt/vmdevices/core.py
+++ b/vdsm/virt/vmdevices/core.py
@@ -54,8 +54,8 @@
self.is_hostdevice = False
def __str__(self):
- attrs = [':'.join((a, str(getattr(self, a, None)))) for a in dir(self)
- if not a.startswith('__')]
+ attrs = [':'.join((a, str(getattr(self, a, None))))
+ for a in vars(self)]
return ' '.join(attrs)
def is_attached_to(self, xml_string):
--
To view, visit
https://gerrit.ovirt.org/68679
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0790b0bc78788e9b418121665e30bbfb48d40be6
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken(a)redhat.com>