>
>
> Anyway, I've got the privacy aspect and bouncing through a proxy bit
> working:
>
> http://pastebin.com/tz8Fcv8t
>
> This results in calls inside the class happening directly and calls
> outside the class being funneled through a proxy class, and attempted
> calls to methods not marked as threadsafe from outside the instance
> failing. So far so good.
>
> Then normally I've be able to do this sort of this - replace this:
>
> class Store(object):
>    __metaclass__ = AttributeHiding
>
>    def __init__(self, **defaults):
>        self.__dict__.update(defaults)
>
> with:
>
> class Actor(object):
>    __metaclass__ = AttributeHiding
>
> class Store(Actor):
>    def __init__(self, **defaults):
>        self.__dict__.update(defaults)
>
> ... and Store would have the same __metaclass__ as Actor and it'd Just
> Work. This also then means people would just subclass Actor for things
> to work like this.
>
> However, I've done something that breaks this, and I'm not sure
> what :-)
>

1. The Actor class (by virtue of its Metaclass) is actually the Proxy class.
2. The Store class is still the plain old Store class.
3. Proxy defines an __init__ method which *must* be called in order for the
proxied object (i.e. either an instance of Actor or Store) to be created.
4. When you call a = Actor(), this is effectively calling Proxy.__init__
and the proxied object is created (see points 1 and 3).
5. When you call s = Store(), you're simply calling plain old
Store.__init__ and not Proxy.__init__ so no proxied object is created (see
point 2).

A quick fix is to ensure Store.__init__ calls the superclass __init__ so
the proxied object is created:

class Store(Actor):
  def __init__(self, **defaults):
    *super(Store, self).init(**defaults)*

... or simply omit the __init__ method from Store!

These quick fixes aren't ideal as they rely on too much knowledge by the
subclass, but they shed light on what's going on.  I'll leave a better fix
as an exercise for the reader ... ;)

Safe

-- 
To post: [email protected]
To unsubscribe: [email protected]
Feeds: http://groups.google.com/group/python-north-west/feeds
More options: http://groups.google.com/group/python-north-west

Reply via email to