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


Groups > comp.lang.python > #6760

Re: returning NotImplemented

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python': 0.08; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'wrote:': 0.14; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'subject:returning': 0.16; 'cc:addr:python-list': 0.17; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; '(or': 0.24; 'code': 0.24; 'object': 0.26; 'raise': 0.28; 'noticed': 0.28; 'all,': 0.30; 'cc:addr:python.org': 0.30; 'second': 0.30; 'does': 0.33; 'header :User-Agent:1': 0.35; 'curious': 0.35; 'perform': 0.37; 'eric': 0.38; 'subject:: ': 0.38; 'should': 0.39; 'got': 0.39; 'your': 0.60; 'received:websitewelcome.com': 0.67; '(after': 0.67; 'received:67.18.68': 0.84; 'abc': 0.91; 'snow': 0.91; 'subject:skip:N 10': 0.93
Date Tue, 31 May 2011 15:18:27 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To Eric Snow <ericsnowcurrently@gmail.com>
Subject Re: returning NotImplemented
References <BANLkTimknB3+bC9ewN1Gft=a=dEU5ik8Lw@mail.gmail.com>
In-Reply-To <BANLkTimknB3+bC9ewN1Gft=a=dEU5ik8Lw@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:1658
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2338.1306879538.9059.python-list@python.org> (permalink)
Lines 15
NNTP-Posting-Host 82.94.164.166
X-Trace 1306879538 news.xs4all.nl 49181 [::ffff:82.94.164.166]:42121
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6760

Show key headers only | View raw


Eric Snow wrote:
> Looking at the ABC code [1], I noticed that Mapping's __eq__ method can 
> return NotImplemented.  This got me curious as to why you would return 
> NotImplemented and not raise a TypeError or a NotImplementedError.  

My understanding is that if your object does not know how to perform the 
desired action you should return NotImplemented; Python will then give 
the other object a chance to perform the operation (after all, it may 
know how), and if the other object also returns NotImplemented then 
Python itself will raise a TypeError.

If the first object were to raise TypeError (or any exception), the 
second object would not get the chance to try.

~Ethan~

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


Thread

Re: returning NotImplemented Ethan Furman <ethan@stoneleaf.us> - 2011-05-31 15:18 -0700

csiph-web