A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-April/064607.html below:

[Python-Dev] rich comparisions and old-style classes

[Python-Dev] rich comparisions and old-style classesFredrik Lundh fredrik at pythonware.com
Sun Apr 30 08:13:40 CEST 2006
trying to come up with a more concise description of the rich
comparision machinery for pyref.infogami.com, I stumbled upon
an oddity that I cannot really explain:

in the attached example below, why is the rich comparision
machinery doing *four* attempts to use __eq__ in the old-
class case?

</F>

$ more test.py

class old:
    def __init__(self, name):
        self.name = name
    def __repr__(self):
        return self.name
    def __eq__(self, other):
        print "EQ", self, other
        return NotImplemented
    def __cmp__(self, other):
        print "CMP", self, other
        return 0

class new(object):
    def __init__(self, name):
        self.name = name
    def __repr__(self):
        return self.name
    def __eq__(self, other):
        print "EQ", self, other
        return NotImplemented
    def __cmp__(self, other):
        print "CMP", self, other
        return 0

a = old("A")
b = old("B")

print a == b

a = new("A")
b = new("B")

print a == b

$ python test.py

EQ A B
EQ B A
EQ B A
EQ A B
CMP A B
True
EQ A B
EQ B A
CMP A B
True




More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4