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


Groups > comp.lang.python > #62193

Re: Type of an object:

Date 2013-12-17 06:50 -0800
From Ethan Furman <ethan@stoneleaf.us>
Subject Re: Type of an object:
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>
Newsgroups comp.lang.python
Message-ID <mailman.4285.1387291826.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/17/2013 02:35 AM, Gregory Ewing wrote:
> Steven D'Aprano wrote:
>> I think I need to see an actual working demonstration, because as far as I can see, type(obj) returns obj.__class__.
>
> Nope:
>
>>>> class C(object):
> ...  def f(self):
> ...   return "Surprise!"
> ...  __class__ = property(f)
> ...
>>>> c = C()
>>>> type(c)
> <class '__main__.C'>
>>>> c.__class__
> 'Surprise!'

I believe the proxying info comes into play with __class__.__name__:

--> class Test:
...   pass
...

--> t = Test()

--> type(t)
<class '__main__.Test'>

--> t.__class__
<class '__main__.Test'>

--> t.__class__.__name__
'Test'

--> t.__class__.__name__ = 'some_proxy'

--> t.__class__.__name__
'some_proxy'

--
~Ethan~

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