Re: Why new Python 2.5 feature "class C()" return old-style class ?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Why new Python 2.5 feature "class C()" return old-style class ?

From: Aahz <aahz@pythoncraft.com>
Date: Mon Apr 17 2006 - 05:32:04 CEST

In article <e1kq0c$cvf$1@news.contactel.cz>,
Petr Prikryl <prikryl@skil.cz> wrote:
>"Aahz" wrote...
>> Bruno Desthuilliers wrote:
>>>Aahz a écrit :
>>>>
>>>> Classic classes are *NOT* deprecated.
>>>
>>>Perhaps not *officially* yet...
>>
>> Not even unofficially. The point at which we have deprecation is when
>> PEP8 gets changed to say that new-style classes are required for
>> contributions.
>
>My question: Could the old classes be treated in a new Python treated
>as new classes with "implicit" base object? (I know the Zen... ;-)
>
>Example: I use usually a very simple classes. When I add "(object)" to
>my class definitions, the code continues to works fine -- plus I have
>new features to use. Why this cannot be done automatically? What could
>be broken in the old code if it was threated so?

Method resolution order is the primary up-front difference, but
introspective code can also have problems. If you're tired of adding
"(object)", put

__metaclass__ = type

at the top of your modules.

-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/
"LL YR VWL R BLNG T S"
Received on Sun Apr 30 23:22:54 2006