Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62243
| Path | csiph.com!usenet.pasdenom.info!news.etla.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!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 | Wed, 18 Dec 2013 11:15:03 +1300 |
| Lines | 33 |
| Message-ID | <bhc0n9Fan00U1@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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net y9F1X/LO5WTrkfZVvEor8wllQ7LJHVgPcihVd9HivctSL2vlcS |
| Cancel-Lock | sha1:CM5sQBTNDN0G19EkzJrftyOC8FU= |
| User-Agent | Mozilla Thunderbird 1.0.5 (Macintosh/20050711) |
| X-Accept-Language | en-us, en |
| In-Reply-To | <52b06902$0$29976$c3e8da3$5496439d@news.astraweb.com> |
| Xref | csiph.com comp.lang.python:62243 |
Show key headers only | View raw
Steven D'Aprano wrote: > Well, that is a surprise, but I don't think that is intended behaviour. I > think that's something which only works by accident. The intention is > that __class__ returns the instance's type, not arbitrary values. Well, a proxy object would obviously return a suitable class-like object. I was just demonstrating that it's possible to override what __class__ returns. I don't think it's an accident, because the weakref module uses this for its proxy objects. >>> import weakref >>> class C(object): ... pass ... >>> c = C() >>> p = weakref.proxy(c) >>> p.__class__ <class '__main__.C'> >>> type(p) <type 'weakproxy'> > If you > try to set it to a non-class on the instance, it fails: For proxying purposes you don't need to be able to set it, but I don't see why you couldn't use a property setter to override that behaviour as well if you really wanted to. -- Greg
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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