Type of an object:

Gregory Ewing greg.ewing at canterbury.ac.nz
Wed Dec 18 06:39:23 EST 2013


Steven D'Aprano wrote:
> It's the *non-class* part I reckon is an accident, or a bug. Telling me 
> that weakproxy sets __class__ to a *class* doesn't argue for or against 
> me.

I wouldn't describe what weakref.proxy is doing as
*setting* __class__ to anything. Rather, it's arranging
things so that when you *get* x.__class__, it returns
something other than type(x). And I expect it's achieving
that effect by exploiting one of the general mechanisms
available for overriding attribute access.

You seem to think it's an "accident" that there is
no protection in place to prevent __class__ access from
being overridden in such a way that it returns something
other than a class.

I suppose you could say that this "works by accident", but
I would say that it simply works. There may not be any
obvious practical *use* for it, but it's not worth
anyone's time to go out of their way to prevent it.

-- 
Greg



More information about the Python-list mailing list