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


Groups > comp.lang.python > #62294

Re: Type of an object:

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Gregory Ewing <greg.ewing@canterbury.ac.nz>
Newsgroups comp.lang.python
Subject Re: Type of an object:
Date Thu, 19 Dec 2013 00:45:02 +1300
Lines 17
Message-ID <bhdg62Fjrb3U1@mid.individual.net> (permalink)
References <mailman.4162.1387158693.18130.python-list@python.org> <52af7bfe$0$29976$c3e8da3$5496439d@news.astraweb.com> <mailman.4265.1387264469.18130.python-list@python.org> <52b0006a$0$29973$c3e8da3$5496439d@news.astraweb.com> <bhann0F1rrsU1@mid.individual.net> <52b06902$0$29976$c3e8da3$5496439d@news.astraweb.com> <bhc0n9Fan00U1@mid.individual.net> <52b0e36b$0$6512$c3e8da3$5496439d@news.astraweb.com> <mailman.4316.1387330505.18130.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net XSdvTfofcXYI+SzuZquA8wqk4+jy8/lQ0elMXf1F1xaZPKX0pq
Cancel-Lock sha1:FLMN2Uif7BAoYC1rlGrtzfhq/AM=
User-Agent Mozilla Thunderbird 1.0.5 (Macintosh/20050711)
X-Accept-Language en-us, en
In-Reply-To <mailman.4316.1387330505.18130.python-list@python.org>
Xref csiph.com comp.lang.python:62294

Show key headers only | View raw


Ethan Furman wrote:
>> This leads to another question: we've now seen two examples where
>> (presumably) the internal type field and __class__ differ. In the
>> weakproxy case, type(obj) returns the internal type field. In the
>> "regular" case, where you set obj.__class__ to a class, type(obj) returns
>> the new (external) type. How the hell does it decide which one to return?

When you set the __class__ of a regular object and it
succeeds, it actually changes the internal type, i.e.
obj->ob_type at the C level.

This is only allowed under certain conditions. Mostly
only for user-defined classes, and only if the layouts
of the old and new instance structs are compatible.

-- 
Greg

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


Thread

Type of an object: ‘obj.__class__’ versus ‘type(obj)’ Ben Finney <ben+python@benfinney.id.au> - 2013-12-16 12:51 +1100
  Re: Type of an object: ‘obj.__class__’ versus ‘type(obj)’ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-16 22:17 +0000
    Re: Type of an object: ‘obj.__class__’ versus ‘type(obj)’ dieter <dieter@handshake.de> - 2013-12-17 08:14 +0100
      Re: Type of an object: ‘obj.__class__’ versus ‘type(obj)’ Steven D'Aprano <steve@pearwood.info> - 2013-12-17 07:42 +0000
        Re: Type of an object: Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-17 23:35 +1300
          Re: Type of an object: Ethan Furman <ethan@stoneleaf.us> - 2013-12-17 06:50 -0800
          Re: Type of an object: Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-17 15:08 +0000
            Re: Type of an object: Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-18 11:15 +1300
              Re: Type of an object: Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-17 23:51 +0000
                Re: Type of an object: Ethan Furman <ethan@stoneleaf.us> - 2013-12-17 17:10 -0800
                Re: Type of an object: Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-19 00:45 +1300
                Re: Type of an object: Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-19 00:39 +1300

csiph-web