Patchwork [10,of,12] upgrade: implement equality for 'improvement' object

login
register
mail settings
Submitter Pierre-Yves David
Date April 11, 2017, 10:47 p.m.
Message ID <0646947aaf15ffa2a0f0.1491950870@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/20118/
State Accepted
Headers show

Comments

Pierre-Yves David - April 11, 2017, 10:47 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1491858603 -7200
#      Mon Apr 10 23:10:03 2017 +0200
# Node ID 0646947aaf15ffa2a0f08f997d1bb699dcc4e612
# Parent  9dccc5b939acea2e559e70024fd5373f9ecc18ce
# EXP-Topic upgraderepo
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 0646947aaf15
upgrade: implement equality for 'improvement' object

Through the code, we use a mix of 'improvement' object and string. Having a
single type would be simpler. For this we need the object to be comparable.

Patch

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -138,6 +138,12 @@  class improvement(object):
         for k, v in kwargs.items():
             setattr(self, k, v)
 
+    def __eq__(self, other):
+        if not isinstance(other, improvement):
+            # This is what python tell use to do
+            return NotImplemented
+        return self.name == other.name
+
 def finddeficiencies(repo):
     """returns a list of deficiencies that the repo suffer from"""
     newreporeqs = localrepo.newreporequirements(repo)