Change in vdsm[master]: MonkeyPatch: fix reverting staticmethods.

nsoffer at redhat.com nsoffer at redhat.com
Sat Jan 18 00:47:12 UTC 2014


Nir Soffer has posted comments on this change.

Change subject: MonkeyPatch: fix reverting staticmethods.
......................................................................


Patch Set 2: Code-Review-1

(1 comment)

Nice catch - but note that this module was not meant to patch classes - hence the naming - module, name, that.

I suggest you modify the names so it is clear that this is not limited to modules.

We also need a new test for this case.

http://gerrit.ovirt.org/#/c/23378/2/tests/monkeypatch.py
File tests/monkeypatch.py:

Line 72:             # sets the function as instancemethod instead of keeping it as
Line 73:             # staticmethod.
Line 74:             if type(that) != type(getattr(module, name)):
Line 75:                 if isinstance(that, types.FunctionType):
Line 76:                     setattr(module, name, staticmethod(that))
Why set wrong value and fix? We can make it simpler and more clear with:

    module, name, that = self.old.pop()

    # In Python 2, setattr wrongly convert a function to unbound method
    # instead of keeping it as a function.
    if insept.isfunction(that):
        that = staticmethod(that)

    setattr(module, name, that)
Line 77: 
Line 78: 
Line 79: #
Line 80: # Monkey patch scope.


-- 
To view, visit http://gerrit.ovirt.org/23378
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ie3100455ab761481f57a93ab8aacc34ac4ab91eb
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>
Gerrit-Reviewer: Antoni Segura Puimedon <asegurap at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes


More information about the vdsm-patches mailing list