Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'true,': 0.05; 'false,': 0.09; 'raises': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'assume': 0.14; '__ne__': 0.16; 'comparisons,': 0.16; 'fuzzy': 0.16; 'kern': 0.16; 'operators,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:operators': 0.16; 'underlying': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'header:User- Agent:1': 0.23; 'interpret': 0.24; '(or': 0.24; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'feature': 0.29; 'robert': 0.30; 'getting': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'classes': 0.35; 'no,': 0.35; 'but': 0.35; 'false': 0.36; 'in.': 0.36; 'two': 0.37; 'problems': 0.38; 'to:addr:python-list': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:n 10': 0.64; 'our': 0.64; '(that': 0.65; 'world': 0.66; 'believe': 0.68; 'anything.': 0.68; 'eco': 0.84; 'terrible': 0.84; 'subject:Proposal': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: Proposal: === and !=== operators Date: Wed, 09 Jul 2014 16:27:42 +0100 References: <53bce8a3$0$2746$c3e8da3$76491128@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 213.1.240.226 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <53bce8a3$0$2746$c3e8da3$76491128@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404919684 news.xs4all.nl 2860 [2001:888:2000:d::a6]:52754 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74259 On 2014-07-09 08:00, Steven D'Aprano wrote: > At the moment, Python has two (in)equality operators, == and != which > call __eq__ and __ne__ methods. Some problems with those: > > > * Many people expect == to always be reflexive (that is, x == x for > every x) but classes which customise __eq__ may not be. > > * The == operator requires __eq__ to return True or False > (or NotImplemented) and raises TypeError if it doesn't, which > makes it impossible to use == with (say) three-valued or fuzzy > logic. No, it doesn't. It can return anything. [~] |1> x = np.arange(5) [~] |2> x == 3 array([False, False, False, True, False], dtype=bool) You can blame Numeric/numpy for that feature getting in. :-) Now certainly, many uses of __eq__, like containment comparisons, do assume that the result is a bool(able). -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco