Prothon Prototypes vs Python Classes

Jeff Epler jepler at unpythonic.net
Mon Mar 29 08:53:02 EST 2004


On Sun, Mar 28, 2004 at 04:40:03PM +0000, Joe Mason wrote:
> In article <mailman.11.1080489481.20120.python-list at python.org>, Jeff Epler wrote:
> >     def __call__(
> > __metaclass__ = PrototypeMeta
> > 
> > class Thing:
> 
> You're missing most of call() there.

whoops .. that was from the moment when I thought "I'd better do
something about calling a prototype" .. just remove it.

> 
> BTW, I've got three pure-python solutions now (four when this one's
> fixed) but it turns out they all suffer from a flaw:
> 
> >>> class TestProto: l = []
> ... 
> >>> class Test2(TestProto): pass
> ... 
> >>> TestProto.l
> []
> >>> Test2.l
> []
> >>> Test2.l.append(0)
> >>> Test2.l
> [0]
> >>> TestProto.l
> [0]
> 
> We really need copy-on-write lists and dicts - and large objects in
> general - for this to work.

Can't you just follow the Python rule for classes with a little
difference?
* if you want some data to be shared by reference among the Prototype
  and all its children, declare it at 'prototype' ('class') scope
* if you don't, create it in __init__

Jeff




More information about the Python-list mailing list