Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'puts': 0.07; 'terry': 0.09; 'jan': 0.10; 'eckhardt': 0.16; 'fallback': 0.16; 'objects?': 0.16; 'received:80.91': 0.16; 'received:80.91.229': 0.16; 'received:gmane.org': 0.16; 'received:list': 0.16; 'received:verizon.net': 0.16; 'reedy': 0.16; 'subject:instance': 0.16; 'subject:type': 0.16; 'subject:unittest': 0.16; 'unexpected': 0.16; 'compare': 0.18; 'changes': 0.19; 'wrote:': 0.21; 'function': 0.22; 'classes,': 0.22; 'header:In-Reply-To:1': 0.22; 'header:User-Agent:1': 0.23; 'library': 0.24; '>>>': 0.24; 'defined': 0.27; 'subject:with': 0.28; 'words,': 0.29; 'yes.': 0.29; 'code': 0.29; 'all.': 0.29; 'two': 0.35; 'sure': 0.36; 'except': 0.36; 'header:X-Complaints-To:1': 0.36; '(for': 0.36; 'reference': 0.36; 'but': 0.36; 'some': 0.37; 'received:org': 0.38; 'to:addr:python-list': 0.39; 'to:addr:python.org': 0.40; 'type': 0.62; 'identity': 0.63; 'different': 0.65; 'built-in': 0.67; 'idea.': 0.72; 'default': 0.81; 'comparisons': 0.84; 'notion': 0.84; 'user-defined': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: unittest: assertRaises() with an instance instead of a type Date: Thu, 29 Mar 2012 11:04:47 -0400 References: 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: 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1333033510 news.xs4all.nl 6971 [2001:888:2000:d::a6]:45411 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22341 On 3/29/2012 3:28 AM, Ulrich Eckhardt wrote: >> Equality comparison is by id. So this code will not do what you want. > > >>> Exception('foo') == Exception('foo') > False > > Yikes! That was unexpected and completely changes my idea. Any clue > whether this is intentional? Is identity the fallback when no equality > is defined for two objects? Yes. The Library Reference 4.3. Comparisons (for built-in classes) puts is this way. "Objects of different types, except different numeric types, never compare equal. Furthermore, some types (for example, function objects) support only a degenerate notion of comparison where any two objects of that type are unequal." In other words, 'a==b' is the same as 'a is b'. That is also the default for user-defined classes, but I am not sure where that is documented, if at all. -- Terry Jan Reedy