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


Groups > comp.lang.python > #6769

Re: returning NotImplemented

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'guido': 0.04; 'behavior,': 0.07; 'interpreter': 0.07; 'raised': 0.07; 'python': 0.08; 'bubble': 0.09; 'deliberately': 0.09; 'exceptions': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'indicates': 0.09; 'message- id:@stoneleaf.us': 0.09; 'not?': 0.09; 'operator,': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'exception': 0.12; 'wrote:': 0.14; '(!)': 0.16; '(assuming': 0.16; 'bugs,': 0.16; 'called,': 0.16; 'function)': 0.16; 'hazard': 0.16; 'received:67.18.44': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'subject:returning': 0.16; 'sure,': 0.16; 'method.': 0.16; 'result,': 0.16; 'call.': 0.19; 'to:name:python-list': 0.19; 'guess': 0.19; 'header:In-Reply-To:1': 0.21; 'code.': 0.22; 'worked': 0.24; "we'd": 0.24; 'function': 0.25; 'later': 0.26; 'object': 0.26; '(even': 0.29; 'instead': 0.29; 'code,': 0.29; 'nested': 0.30; 'done': 0.32; 'does': 0.33; 'to:addr:python-list': 0.33; 'handling': 0.33; 'too': 0.33; 'rather': 0.34; 'expensive': 0.34; 'header:User-Agent:1': 0.35; 'function.': 0.35; 'several': 0.36; 'thread': 0.37; 'another': 0.37; 'could': 0.38; 'but': 0.38; 'earlier': 0.38; 'eric': 0.38; 'returning': 0.38; 'signal': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'should': 0.39; 'called': 0.39; 'returned': 0.39; 'to:addr:python.org': 0.39; 'getting': 0.40; "couldn't": 0.40; 'easily': 0.60; 'more': 0.60; 'below': 0.61; 'matter': 0.63; 'levels': 0.63; 'received:websitewelcome.com': 0.67; 'stated': 0.67; 'imagine': 0.72; 'directly?': 0.84; 'received:gateway04.websitewelcome.com': 0.91; 'snow': 0.91; 'subject:skip:N 10': 0.93
Date Tue, 31 May 2011 17:30:18 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To python-list <python-list@python.org>
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]:1906
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
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.2345.1306887447.9059.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 82.94.164.166
X-Trace 1306887447 news.xs4all.nl 49042 [::ffff:82.94.164.166]:56503
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6769

Show key headers only | View raw


Eric Snow wrote:
> Guido indicates earlier in the thread that NotImplemented is used so 
> that you know that it came from the function that you directly called, 
> and not from another call inside that function.  Why does it matter if 
> it came directly from the function or not?  And couldn't the 
> NotImplemented still have come from a call inside the operator, rather 
> than directly?

An exception can bubble up from several levels below the original call. 
  Returning NotImplemented (even if returned from another internal 
function) still has to be deliberately done by the original method.

Later in the thread it is also stated that while exception handling 
performance is not too different in C code, it is very much more 
expensive in Python code.

As to why it would matter if whether the return was from the directly 
called method vs some nested method... not sure, but I would hazard a 
guess that by returning NotImplented the interpreter knows everything 
worked as it should have (assuming no bugs, of course); whereas an 
exception could easily _not_ have come from the directly called method. 
  Imagine if the methods raised exceptions to signal normal behavior, 
and some object was buggy -- for __eq__ we'd end up with a False result, 
instead of getting the exception propagated. (!)

~Ethan~

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


Thread

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

csiph-web