Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52342

Re: Python Basic Doubt

References (2 earlier) <52067FDA.2030908@gmail.com> <5206B527.6080700@islandtraining.com> <CAPTjJmoM=MU2eqa2i_5_RbveXMqScQqu_uFjonwdrZX7Vsc49g@mail.gmail.com> <5206DDED.8030506@islandtraining.com> <ku6p6b$cbd$1@ger.gmane.org>
Date 2013-08-11 02:32 +0100
Subject Re: Python Basic Doubt
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.450.1376184743.1251.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Aug 11, 2013 at 2:25 AM, Terry Reedy <tjreedy@udel.edu> wrote:
> On 8/10/2013 8:42 PM, Gary Herron wrote:
>
>> But for each of your examples, using "==" is equivalent to using "is".
>> Each of
>>      if something == None
>>      if device == _not passed
>>      if device != None
>> would all work as expected.  In none of those cases is "is" actually
>> needed.
>
>
> class EqualAll:
>     def __eq__(self, other): return True

That's a contrived example, of course, but it's easy to have a bug in
__eq__ that results in the same behaviour. I can't imagine any code
that would actually WANT that, unless you're trying to represent
Animal Farm.

class EqualAll:
    def __eq__(self, other):
        if (isinstance(other, pig): return 3   # Some are more equal than others
        return True

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python Basic Doubt Chris Angelico <rosuav@gmail.com> - 2013-08-11 02:32 +0100

csiph-web