Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-11-01 19:01:57


----- Original Message -----
From: "Barry Scott" <barry_at_[hidden]>

> > Sorry, I'm a bit confused, as it seems to work for me with only __dict__
> > support, and built-in Python classes don't have a __methods__ attribute
(at
> > least, not in Python 1.5.2):
>
> I think the idea in Python dir is to allow a type to have methods
> and members that are not in the __dict__ and thus cannot be changed
> without the type's code getting involved.

Aha.

> In CXX __methods__ lists the functions of the type that
> are public. They are not in __dict__ and cannot be damaged
> from Python code. CXX does not support __members__ by default.
>
> I wonder if it is possible to remove a function from a py_cpp type
> by assigning into the __dict__ from python.

Yes, and that would probably cause it to malfunction slightly. To correct
this problem I will need to wrap the __dict__ in another type which
intervenes on modification of the __dict__ and recalculates which method
slots should be filled in. This is a low-priority fix for me, though,
considering that native Python also has problems in the area of dynamic
class modification. This code snippet is for your amusement:

>>> class A:
            ... def __getattr__(self, name):
            ... return 'A.__getattr__'
            ...
>>> class B(A): pass
            ...
>>> class C(B): pass
            ...
>>> C().x
            'A.__getattr__'
>>> B.__bases__ = () # B and C should no longer have a
__getattr__, now
>>> C().x
            'A.__getattr__'

oops-so-to-speak-ly y'rs,
dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk