[Python-3000] Metaclasses in Python 3000: Draft 2
Steven Bethard
steven.bethard at gmail.com
Wed Mar 14 17:55:23 CET 2007
On 3/14/07, Talin <talin at acm.org> wrote:
> PEP: xxx
> Title: Metaclasses in Python 3000
Looks good.
> # The metaclass
> class OrderedClass(type):
>
> # The custom dictionary
> class member_table(dict):
> def __init__(self):
> self.member_names = []
>
> def __setitem__(self, key, value):
> # if the key is not already defined, add to the
> # list of keys.
> if key not in self:
> self.member_names.append( key )
>
> # Call superclass
> dict.setitem(self, key value)
Should probably be ``dict.__setitem__(self, key, value)``.
> # The prepare function
> @classmethod
> def __prepare__(cls, name, bases): # No keywords in this case
> return self.member_table()
Should probably be:
@classmethod
def __prepare__(meta, name, bases):
return meta.member_table()
Perhaps __prepare__ should be special-cased like __new__ so that it's
always a @classmethod?
STeVe
--
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
--- Bucky Katt, Get Fuzzy
More information about the Python-3000
mailing list