[Cython] __getattribute__
Peter Todd
pete at petertodd.org
Sun May 4 07:15:32 CEST 2008
On Wed, Apr 30, 2008 at 06:17:31PM -0700, Robert Bradshaw wrote:
> On Apr 29, 2008, at 5:42 PM, Peter Todd wrote:
>
> >Is there a __getattribute__ work-alike in Cython?
> >
> >Essentially I need direct control over an objects tp_getattro and
> >tp_setattro slots to implement a wrapper class. Specificly
> >wrapped.__class__ should go to the wrapped objects class attribute,
> >not
> >the wrapping objects __class__ attribute.
> >
> >__getattr__ outputs C-source that includes a call to
> >PyObject_GenericGetAttr first, and won't run my code if that call
> >succeeds.
> >
> >Thanks,
> >
> >Peter
>
> Not that I'm aware of, though I'd imagine that implementing
> __getattribute__ (if it exists) as being called at the top of this
> function would be fairly easy to do. One would want to match Python
> symantics exactly.
Here's my first patch. This correctly implements __getattribute__ and
__getattr__ in the single class case. FWIW I also have a mercurial tree
if it'd be better to pull from it than apply patches.
I'm working on making subclasses behave correctly, I've got test cases
written up showing where things fail, but no solutions to that written
yet. The slot_tp_getattro stuff Stefan mentioned is useful though.
--
http://petertodd.org 'peter'[:-1]@petertodd.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: __getattribute__.patch
Type: text/x-diff
Size: 4799 bytes
Desc: not available
Url : http://codespeak.net/pipermail/cython-dev/attachments/20080504/376ae4c6/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://codespeak.net/pipermail/cython-dev/attachments/20080504/376ae4c6/attachment.pgp
More information about the Cython-dev
mailing list