Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.04; 'instance,': 0.05; 'received:verizon.net': 0.07; 'terry': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'tuple': 0.09; 'output': 0.10; 'am,': 0.12; 'protocol': 0.15; 'artificially': 0.16; 'reedy': 0.16; 'sequence.': 0.16; 'subject:function': 0.16; 'wrote:': 0.16; 'jan': 0.19; 'input': 0.21; 'appropriate': 0.22; "doesn't": 0.22; 'header:In-Reply- To:1': 0.22; 'interface': 0.23; 'documented': 0.23; 'generic': 0.24; 'testing': 0.26; 'function': 0.27; 'producing': 0.28; "skip:' 10": 0.29; 'specified': 0.30; 'words,': 0.32; 'typically': 0.32; 'list': 0.32; 'header:User-Agent:1': 0.33; 'instead': 0.33; 'to:addr:python-list': 0.33; 'function.': 0.34; 'test.': 0.34; 'header:X-Complaints-To:1': 0.34; 'example,': 0.36; 'checks': 0.36; 'list,': 0.37; 'but': 0.37; 'received:org': 0.37; 'steven': 0.38; 'some': 0.38; 'should': 0.38; 'possible,': 0.38; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'range': 0.60; 'more': 0.61; 'your': 0.61; 'limit': 0.67; 'hand,': 0.76; 'subject:value': 0.84; 'checks.': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: verify the return value of a function Date: Fri, 20 Jan 2012 15:42:45 -0500 References: <4f198330$0$29987$c3e8da3$5496439d@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: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: <4f198330$0$29987$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327092190 news.xs4all.nl 6936 [2001:888:2000:d::a6]:56048 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19165 On 1/20/2012 10:07 AM, Steven D'Aprano wrote: > What should be avoided, when possible, is over-reliance on isinstance > checks instead of protocol or interface checks. For example, don't check > for a list if your function doesn't *need* a list but would be happy with > a tuple or some other sequence. In other words, do not use isinstance to artificially limit the input domain of a function. The generic or polymorphic nature of (builtin) operators and functions is a major feature of Python. On the other hand, the output range of a function is typically much more limited as to type. Complete testing requires testing the specified output type. For instance, sorted(iterable) is documented as producing a sorted list, so 'type(output) is list' is an appropriate test. -- Terry Jan Reedy