Amaury Forgeot d'Arc added the comment:
When designing a metaclass, you should override __new__, not __init__:
class MetaNode(type):
def __new__(cls, name, bases, cdict):
cdict['z'] = name
return type.__new__(cls, name, bases, cdict)
class Node(object):
__metaclass__ = MetaN
New submission from L. Peter Deutsch:
In the following, dir(Node) should include the name 'z', and Node.z
should be 'Node'. However, dir(Node) does not include 'z', and Node.z is
undefined (AttributeError). This is directly contrary to the Python
documentation, which says "metaclasses can modify