Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'importing': 0.04; 'class,': 0.07; 'objects,': 0.07; 'imported': 0.09; 'instantiated': 0.09; 'other,': 0.09; "hasn't": 0.15; 'fiddle': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'oddity': 0.16; 'twice.': 0.16; 'wrote:': 0.17; 'basically': 0.17; 'instance': 0.17; 'module': 0.19; 'file.': 0.20; 'sort': 0.21; 'import': 0.21; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'separate': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject:/': 0.28; 'van': 0.29; 'class': 0.29; 'fri,': 0.30; 'to:addr:python- list': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'nov': 0.35; 'subject:?': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'little': 0.39; 'header:Received:5': 0.40; "you've": 0.61; '30,': 0.62; 'different': 0.63; 'show': 0.63; 'state.': 0.71; 'as:': 0.75 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=WaQ3Jntws0UB+/3x8ocayr7BZ/0jdtd7gf48G4/XjA0=; b=zQKttB47si/ank/nDiZZ7L8E2a9wiztrgcAQyHYi8pLQUP8Gr9My1EDs3bTNF1MJVF xC3UiXdtVkYNChg9LdRxzd1uGdITK+wD61HSslD6UcA6SNQDX1U/B3G8jP0NrzhYZTx6 +OSBjPA5RrftmBlYlXiqlIpDVVJP70Yi+6S7dStvaLOZO/iCNBaOr/MrYEFjohn6TEWx S2/qS6jfYRQkEoYmvGOLE44z0ngl2Sz3aLLSuvHBYUf21MnVuwLWUwjd3cOLyTcvUicb 4+64X03CLbQRwCvbWoS4HJupGt44cf4Xpcs6g/f5BdCCQSr0mL4d19sBzP/whR0rNt5y YSLQ== MIME-Version: 1.0 In-Reply-To: <1cad82ec-8241-486c-9c8b-c7d6ca427adc@googlegroups.com> References: <1cad82ec-8241-486c-9c8b-c7d6ca427adc@googlegroups.com> Date: Fri, 30 Nov 2012 02:08:20 +1100 Subject: Re: weird isinstance/issubclass behavior? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 1354201710 news.xs4all.nl 6890 [2001:888:2000:d::a6]:44875 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34068 On Fri, Nov 30, 2012 at 1:59 AM, lars van gemerden wrote: > Basically if i import a class as: > > from mod1.mod2 import A > > or: > > from mod0.mod1.mod2 import A > > which both result in importing the same class, a call to isinstance(inst, A) in another module can have a different output. What you may be seeing there is that you've imported the module twice. There are two entirely separate module objects, taken from the same file. Something instantiated from one class isn't an instance of the other class even if they're indistinguishable classes; a little monkeypatching might show you what's going on (fiddle with one class, check the other, fiddle hasn't happened). As a general rule, importing a module in different ways is considered dangerous. Be consistent, and then this sort of oddity won't occur - and you also won't have other oddities, eg with other global state. ChrisA