Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34068

Re: weird isinstance/issubclass behavior?

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 <rosuav@gmail.com>
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 <rosuav@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.365.1354201710.29569.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Fri, Nov 30, 2012 at 1:59 AM, lars van gemerden <lars@rational-it.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

weird isinstance/issubclass behavior? lars van gemerden <lars@rational-it.com> - 2012-11-29 06:59 -0800
  Re: weird isinstance/issubclass behavior? Chris Angelico <rosuav@gmail.com> - 2012-11-30 02:08 +1100
  Re: weird isinstance/issubclass behavior? lars van gemerden <lars@rational-it.com> - 2012-11-29 08:07 -0800
  Re: weird isinstance/issubclass behavior? Terry Reedy <tjreedy@udel.edu> - 2012-11-29 16:00 -0500

csiph-web