Change in vdsm[master]: debuging: Use __repr__ instead of __str__

danken at redhat.com danken at redhat.com
Thu Dec 3 11:20:52 UTC 2015


Dan Kenigsberg has submitted this change and it was merged.

Change subject: debuging: Use __repr__ instead of __str__
......................................................................


debuging: Use __repr__ instead of __str__

Recently we are implementing __str__ for objects, for improved logging:

    logging.debug("Discarding task %s", self.task)

We are using the style used by Python:

    >>> threading.RLock()
    <_RLock owner=None count=0>

Implementing __str__ is fine for logging, but when using the Python
interactive shell (e.g, manhole), the output is not very useful:

    >>> class Foo(object):
    ...     def __str__(self):
    ...             return "<Foo bar=2 at 0x%x>" % id(self)
    ...
    >>> f = Foo()
    >>> f
    <__main__.Foo object at 0x7f5f85441c90>

For debugging, we should implement __repr__ instead of __str__.
According to the language reference[1], when using str(), if object does
not implement __str__, its __repr__ is used.

This patch replaces most relevant __str__ methods with __repr__. Some
methods needs more work and left for later.

One instance implementing __repr__ that return the same output as
object.__repr__ was removed.

[1] https://docs.python.org/2/reference/datamodel.html#object.__repr__

Change-Id: I2fd724e32dfde1ca484343730f2e55c37a59fdf3
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
Reviewed-on: https://gerrit.ovirt.org/48865
Reviewed-by: Ido Barkan <ibarkan at redhat.com>
Reviewed-by: Milan Zamazal <mzamazal at redhat.com>
Reviewed-by: Francesco Romani <fromani at redhat.com>
Reviewed-by: Piotr Kliczewski <piotr.kliczewski at gmail.com>
Reviewed-by: Dan Kenigsberg <danken at redhat.com>
---
M lib/vdsm/executor.py
M tests/nettestlib.py
M vdsm/storage/storageServer.py
M vdsm/virt/periodic.py
M vdsm/virt/sampling.py
5 files changed, 6 insertions(+), 11 deletions(-)

Approvals:
  Piotr Kliczewski: Looks good to me, but someone else must approve
  Nir Soffer: Verified; Passed CI tests
  Ido Barkan: Looks good to me, but someone else must approve
  Dan Kenigsberg: Looks good to me, approved
  Francesco Romani: Looks good to me, but someone else must approve
  Milan Zamazal: Looks good to me, but someone else must approve

Objections:
  Jenkins CI: Failed CI tests



-- 
To view, visit https://gerrit.ovirt.org/48865
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2fd724e32dfde1ca484343730f2e55c37a59fdf3
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Ido Barkan <ibarkan at redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Milan Zamazal <mzamazal at redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: Piotr Kliczewski <piotr.kliczewski at gmail.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>


More information about the vdsm-patches mailing list