Type of an object: ‘obj.__class__’ versus ‘type(obj)’

Ben Finney ben+python at benfinney.id.au
Mon Dec 16 02:09:20 EST 2013


Chris Angelico <rosuav at gmail.com> writes:

> On Mon, Dec 16, 2013 at 3:50 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> > Should we expect (ignoring pathological cases) the assertion
> > ‘type(obj) is obj.__class__’ to hold true? If not, under what
> > circumstances would it be sensible for those to differ?
>
> By "pathological cases", do you mean arbitrarily changing
> obj.__class__

By “pathological cases” I mean to acknowledge that, in Python, of course
any attribute or function can be changed merely to thwart some rule
about how those attributes and functions will generally behave — and to
exclude such cases from the question where there is no purpose to the
case other than the thwarting of the general rule.

-- 
 \         “I still have my Christmas Tree. I looked at it today. Sure |
  `\               enough, I couldn't see any forests.” —Steven Wright |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list