Fix bugs in example found by Georg Brandl.

This commit is contained in:
Guido van Rossum 2007-06-01 23:17:14 +00:00
parent 3fa034da0d
commit 712dd58b08
1 changed files with 3 additions and 3 deletions

View File

@ -197,7 +197,7 @@ Example:
self.member_names.append(key)
# Call superclass
dict.setitem(self, key, value)
dict.__setitem__(self, key, value)
# The metaclass
class OrderedClass(type):
@ -208,12 +208,12 @@ Example:
return member_table()
# The metaclass invocation
def __init__(self, name, bases, classdict):
def __new__(cls, name, bases, classdict):
# Note that we replace the classdict with a regular
# dict before passing it to the superclass, so that we
# don't continue to record member names after the class
# has been created.
result = type(name, bases, dict(classdict))
result = type.__new__(cls, name, bases, dict(classdict))
result.member_names = classdict.member_names
return result