Home

On Sep 1, 6:07 pm, Steve Holden <st...@holdenweb.com> wrote:
<snip>
>
> Debugging with Wing IDE and examining the classes at a breakpoint shows
> this to be true (even after Y's __metaclass__ assignment is commented out):
>
> >>> X.__metaclass__
> <class '__main__.Meta'>
> >>> Y.__metaclass__
> <class '__main__.Meta'>
> >>>

For the benefit of the readers I will just point out that in order
to determine the metaclass of a class it is far better NOT to relay on
the
__metaclass__ attribute. The right thing to to is to look at the
__class__
attribute, or to use type. Here is a (made up) example
where .__metaclass__ gives
the wrong result:


In [9]: class M(type): pass
...:

In [10]: class B: __metaclass__ = M
....:

In [11]: B.__metaclass__ = None # now the hook is set to None, but the
metaclass does not change

In [12]: B.__class__
Out[12]: <class '__main__.M'>

Michele Simionato

previous
next

Re: Querying Graphics Card Name
Re: Thread-safe file locking
Re: Development for dual core machine
Re: unexpected behavior: did i create a pointer?
Frustrating bug in C++ program
Mimo Wszystko
Krwinka
Dzieci Niczyje
Fundacja Hobbit
Fundacja Avalon