Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; 'distinct': 0.05; 'attribute': 0.07; 'subject:object': 0.07; 'variable,': 0.07; 'expected.': 0.09; 'foo': 0.09; 'foo,': 0.09; 'am,': 0.12; 'classes,': 0.13; 'case.': 0.15; 'behavior?': 0.16; 'curious,': 0.16; 'failed.': 0.16; 'it...': 0.16; 'subject: \n ': 0.16; 'subject:behavior': 0.16; 'url:browse_thread': 0.16; 'url:thread': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'this?': 0.19; 'thorough': 0.21; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'somewhere': 0.23; 'statement': 0.23; 'changed': 0.23; 'dictionary': 0.23; 'suggests': 0.23; '\xa0if': 0.23; 'cc:2**0': 0.24; 'tests': 0.25; 'classes': 0.26; 'module': 0.26; 'import': 0.27; 'produced': 0.28; 'message-id:@mail.gmail.com': 0.28; 'worked': 0.29; 'problem': 0.29; 'cc:addr:python.org': 0.29; 'class': 0.29; 'poster': 0.30; 'ran': 0.30; 'yesterday,': 0.30; 'anyone': 0.31; 'regardless': 0.31; 'version': 0.32; 'thu,': 0.32; 'actually': 0.33; 'rather': 0.33; 'there': 0.33; 'normally': 0.34; 'curious': 0.34; 'keys': 0.34; 'subject:/': 0.35; 'url:python': 0.36; 'starting': 0.36; 'uses': 0.36; 'thread': 0.37; 'two': 0.37; 'run': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; 'another': 0.37; 'think': 0.37; 'seeing': 0.38; 'went': 0.38; 'clearly': 0.39; 'should': 0.39; 'else': 0.39; 'absolute': 0.39; 'difference': 0.40; '2011': 0.61; 'url:groups': 0.64; 'believe': 0.65; 'proved': 0.67; 'why?': 0.77; 'nathan': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=RdkeacZK7IkGrpfl9269Udu1kOpDqdwMCjJHbdohjBY=; b=h8U0A9zcTiQ6S/y+HMe2i88L70dgIvgyAEylLMF8elUda4nLfkSuhTGq1QZSMkcbiS s8YgoX/bahiwcu6/RP6nalTXttsdGPHkmxS6UKom9LvXS/AXfqQJ5W6V0565y31ZINtA i3HSAlyBMMAxrHo4R7JY+6UXKlwDGu+tB8uyI= MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Thu, 15 Dec 2011 11:03:40 -0700 Subject: Re: Odd behavior of object equality/identity in the context of relative vs fully qualified imports To: Nathan Rice Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323972253 news.xs4all.nl 6899 [2001:888:2000:d::a6]:34024 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17291 On Thu, Dec 15, 2011 at 7:34 AM, Nathan Rice wrote: > I just ran into this yesterday, and I am curious if there is a > rational behind it... > > I have a class that uses a dictionary to dispatch from other classes > (k) to functions for those classes (v). =A0I recently ran into a bug > where the dictionary would report that a class which was clearly in > the dictionary's keys was giving a KeyError. =A0id() produced two > distinct values, which I found to be curious, and > issubclass/isinstance tests also failed. =A0When I inspected the two > classes, I found that the only difference between the two was the > __module__ variable, which in one case had a name relative to the > current module (foo), and in another case had the fully qualified name > (bar.foo). =A0When I went ahead and changed the import statement for the > module to import bar.foo rather than import foo, everything worked as > expected. =A0My first thought was that I had another foo module in an > old version of the bar package somewhere on my pythonpath; =A0After a > thorough search this proved not to be the case. > > Has anyone else run into this? =A0Is this intended behavior? =A0If so, wh= y? I think this may be the same problem that the poster in this thread encount= ered: http://groups.google.com/group/comp.lang.python/browse_thread/thread/961a90= 219a61e19d/9ed06601603b58d4 Normally I believe the __module__ attribute should be fully qualified regardless of whether the import was absolute or relative. That you're not seeing this suggests that the "relative" import may actually be an absolute import starting from a different sys.path entry.