Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; 'context': 0.04; 'distinct': 0.05; 'bug.': 0.07; 'names.': 0.07; 'subject:object': 0.07; 'variable,': 0.07; 'dependency': 0.09; 'expected.': 0.09; 'foo': 0.09; 'foo,': 0.09; 'top-level': 0.09; 'am,': 0.12; 'classes,': 0.13; 'case.': 0.15; 'circular': 0.15; 'behavior?': 0.16; 'bug).': 0.16; 'chance?': 0.16; 'curious,': 0.16; 'failed.': 0.16; 'guessing': 0.16; 'instantiated': 0.16; 'it...': 0.16; 'sequence.': 0.16; 'subject: \n ': 0.16; 'subject:behavior': 0.16; 'worse,': 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; 'module,': 0.23; '\xa0if': 0.23; 'creating': 0.25; 'loaded': 0.25; 'tests': 0.25; 'classes': 0.26; 'module': 0.26; "i'm": 0.26; 'import': 0.27; 'produced': 0.28; 'right.': 0.28; 'script': 0.28; 'message-id:@mail.gmail.com': 0.28; 'generic': 0.29; 'partial': 0.29; 'worked': 0.29; 'problem': 0.29; 'class': 0.29; '(unless': 0.30; 'imported': 0.30; 'ran': 0.30; 'yesterday,': 0.30; 'anyone': 0.31; 'version': 0.32; 'sufficient': 0.32; 'thu,': 0.32; 'actually': 0.33; 'rather': 0.33; 'there': 0.33; 'received:209.85.160': 0.33; 'to:addr:python-list': 0.34; 'curious': 0.34; 'keys': 0.34; 'changing': 0.35; 'subject:/': 0.35; 'received:209.85.160.46': 0.35; 'received:mail- pw0-f46.google.com': 0.35; 'file': 0.36; 'uses': 0.36; 'to:name :python-list': 0.37; 'two': 0.37; 'run': 0.37; 'received:google.com': 0.37; 'another': 0.37; 'using': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'went': 0.38; 'clearly': 0.39; 'else': 0.39; 'called': 0.40; "it's": 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'difference': 0.40; 'more': 0.61; '2011': 0.61; 'your': 0.61; 'full': 0.62; 'chain': 0.66; 'proved': 0.67; 'verified': 0.73; 'why?': 0.77; '09:34': 0.84; 'nathan': 0.84; '\xa0but': 0.84; 'items,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=tqMIjIomk44UUihl4T0AEsVm7v5SzbrTDRvDh32Mrx4=; b=g+0Fa9rdkFoMY9MgJrNGviNcpo7pcXezpTsXXwttHm2bV1eKNjgLdnI4KGlDrJIDr5 JPbGfQxM9kUUN1yoFhhpho9yNc2zbr1gVhSny57M/bjNKg3GC2a1AknSkNyVA+JXwuzE MPoRLSnpKCXwFGbOdZOMOe9Hi8TypZFW1/hxY= MIME-Version: 1.0 In-Reply-To: <4EEA0D83.6070807@davea.name> References: <4EEA0D83.6070807@davea.name> Date: Thu, 15 Dec 2011 12:11:45 -0500 Subject: Re: Odd behavior of object equality/identity in the context of relative vs fully qualified imports From: Nathan Rice To: python-list Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323969109 news.xs4all.nl 6844 [2001:888:2000:d::a6]:33495 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17282 It would be more work than I want to go into to provide full context (unless it is to file a bug report, if it actually is a bug). I verified that there are no cyclical dependency issues using snakefood, and I doublechecked that just changing the import from full to partial name is sufficient to reintroduce the bug. Can I get confirmation that this is not expected behavior? I will go ahead and file a bug report it that is the case. Nathan On Thu, Dec 15, 2011 at 10:08 AM, Dave Angel wrote: > On 12/15/2011 09: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, w= hy? >> >> Nathan > > Hard to tell with such generic information. =A0But I'm guessing you impor= ted > your script from some other module, creating a circular import sequence. > =A0The circular can be a problem in its own right. =A0But even worse, if = the > script is part of the chain is that it's loaded twice, with different nam= es. > =A0And any top-level items, such as classes, will be instantiated twice a= s > well. =A0is your script called foo.py by any chance? > > -- > > DaveA >