New inited instance of class?

Peter Otten __peter__ at web.de
Sun Dec 7 13:33:33 EST 2003


Francis Avila wrote:

>>You can do it on a per-file basis by putting
>>
>>__metaclass__ = type
>>
>>once before the class definitions.
> 
> That strikes me as a very *bad* idea, because it's no longer obvious that
> the classes themselves are new-style, and the OP might develop a bad habit
> of using this to avoid typing '(object)' all the time.  (Or he might show
> us all for fools, if ':' becomes shorthand for '(object):'.)

I indeed expect the classic/new-style class schism to go away even before
3.0 and am looking forward to remove both (object) in class A(object): and
__metaclass__ = type, which I expect to be equally *not* hard :-)
 
> Aside from that, metaclasses are a more advanced and less-commonly-used
> feature of classes, and therefore probably more vulnerable to change.  I
> know it should work, but am uneasy that it might manifest some unexpected
> behavior (or bug).

For the above recipe to work you need not know what metaclasses are. I'm not
in the ignorance is good camp, though. The more people play with
metaclasses (are there any in production yet?), the sooner the strengths
and weaknesses of this construct will reveal.

If you have the appropriate tests and can make your program pass them by
providing an explicit object superclass instead of the __metaclass__ line,
the fix should be a breeze.


Peter




More information about the Python-list mailing list