[Yum-devel] RFC: Package object comparison -- do we need a slight change?

Jeremy Katz katzj at redhat.com
Thu Oct 12 02:08:28 UTC 2006


So, as it stands right now, we have nice and rich comparison operators
for packages.  foo-1.0-1 < foo-2.0-1 works nicely, etc.  The problem
starts to come in when we get to equality with multiple arches.  Should
foo-1.0-1.i386 == foo-1.0-1.x86_64?  Right now, the answer is yes, but
that breaks trying to see if a specific package is already found in a
list and other such cases.

So, the options (I can think of) are basically
a) Live with it -- if you're trying to check if a package is in a list
or if two packages are actually the same, you have to do equality and
then an arch check.  I think this kind of breaks the principle of least
surprise and is likely to lead to bugs in API users[1]
b) Make the change so that equality of packages also takes into account
arch[2].  This would be a slight semantic change, but I'm not sure I can
think of a case where this _wouldn't_ be what you expect
c) Make the change so the equality of packages takes into account arch
and then also make it so that you have to do other rich comparisons on
po.version or the like.  I'm not a big fan of this as it i) breaks API
users in a big way and ii) breaks easy sorting which is a nice bonus
we've gotten.  

Other people's thoughts?

Jeremy

[1] It's already bitten at least anaconda... I haven't gone to do a
comprehensive check through the tree to see if it breaks anything else
[2] Proposed patch would be something like the following
Index: yum/packages.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/packages.py,v
retrieving revision 1.73
diff -u -u -r1.73 packages.py
--- yum/packages.py     2 Oct 2006 14:42:55 -0000       1.73
+++ yum/packages.py     12 Oct 2006 02:03:01 -0000
@@ -210,12 +210,12 @@
         return False
 
     def __eq__(self, other):
-        if comparePoEVR(self, other) == 0:
+        if comparePoEVR(self, other) == 0 and self.arch == other.arch:
             return True
         return False
 
     def __ne__(self, other):
-        if comparePoEVR(self, other) != 0:
+        if comparePoEVR(self, other) != 0 and self.arch != other.arch:
             return True
         return False
        





More information about the Yum-devel mailing list