Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'operator': 0.03; 'cache': 0.07; 'pypy': 0.07; 'immutable': 0.09; 'integers': 0.09; 'meaningful': 0.09; 'raises': 0.09; 'things,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'suggest': 0.14; '"is': 0.16; '"is"': 0.16; '__ne__': 0.16; 'backwards': 0.16; 'behave': 0.16; 'fuzzy': 0.16; 'nan': 0.16; 'objects.': 0.16; 'operators,': 0.16; 'sorts': 0.16; 'subject:operators': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; '(you': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'cc:addr:python.org': 0.22; '(or': 0.24; 'cc:2**0': 0.24; 'equivalent': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:wiki': 0.31; 'breaking': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'covered': 0.32; '(e.g.': 0.33; "i'd": 0.34; 'classes': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'similar': 0.36; 'url:org': 0.36; 'should': 0.36; 'behind': 0.37; 'two': 0.37; 'problems': 0.38; 'expect': 0.39; 'even': 0.60; 'most': 0.60; 'matter': 0.61; 'first': 0.61; 'guarantee': 0.63; 'skip:n 10': 0.64; 'choose': 0.64; 'different': 0.65; 'great': 0.65; '(that': 0.65; 'anything.': 0.68; 'jul': 0.74; 'much,': 0.84; 'scenes': 0.84; 'url:php': 0.85; 'same,': 0.91; 'subject:Proposal': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=lwIMftIuEtkxrv00pcaifdH2iMXMhJVRp7Y7QbPWG5o=; b=LVLyGcf50TCJ/fdITJzIcpgwpe3ptRIFcYZLNtZbw7tGuMZIq1tJ0OUVtD+A8L79dt pxO3kEZYHGxHlI1cRdSlBqMn566ZgN4J+IVCl65zHnxoGvQT0U+NKmALn3TmTjd78NbT YF5V9r5rBtBYj1N3+k2JNVgXJ+tVIM4lV4i/OpJX/FOgF5wuo37m8WmFBVVeDE9hwENf VEhjPwz1YozeQ5xHYhEMkEs4uo3tqozYpvzlyIVnV71ZEG/zwMe7Nt5vjo69JVTDK8uN Ihozr3n7FFGZ1Uo60xCoGgUDlyEM8JrTEMZJ6bo2ULmklge1o7MwQPhqURkthXi0J8u0 gyfw== X-Received: by 10.224.112.131 with SMTP id w3mr72666206qap.68.1404907341747; Wed, 09 Jul 2014 05:02:21 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <53bce8a3$0$2746$c3e8da3$76491128@news.astraweb.com> References: <53bce8a3$0$2746$c3e8da3$76491128@news.astraweb.com> From: Devin Jeanpierre Date: Wed, 9 Jul 2014 05:01:41 -0700 Subject: Re: Proposal: === and !=== operators To: "Steven D'Aprano" Content-Type: text/plain; charset=UTF-8 Cc: "comp.lang.python" 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404907345 news.xs4all.nl 2876 [2001:888:2000:d::a6]:40375 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74248 On Wed, Jul 9, 2014 at 12:00 AM, 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. Counter-proposal: The second use case doesn't matter that much, and can be added to == without breaking backwards compatibility meaningfully. The first case is covered by all sorts of things, but I'd suggest that the most meaningful way in which nan "is the same as" nan is that they both behave the same, as objects. The Python "is" operator returns True when two objects are identical. Is it a great leap to guarantee, in Python, that equivalent immutable objects are always identical? Then float('nan') is float('nan') should always return True. We already implicitly allow that a Python implementation may choose to do this (e.g. small integers are cached), but it isn't so hard to guarantee it. (You don't even have to cache anything. PyPy makes things is-identical even when they are behind the scenes different objects in memory, IIRC.) See also http://wiki.ecmascript.org/doku.php?id=harmony:egal , which is a similar proposal for ES6. -- Devin