[Pyrex] status of weakref support?

Lenard Lindstrom len-l at telus.net
Sun Dec 12 19:28:47 CET 2004


On Sat, 11 Dec 2004 20:36:48 +0100 Martijn Faassen <faassen at infrae.com> wrote:

> Hi there,
> 
> I read the previous thread about weakref support in Pyrex, and I'm using 
>   the following hack now in lxml:
> 
> cdef class ElementBase:
>       ...
> 
> class Element(ElementBase):
>      __slots__ = ['__weakref__']
> 
> Unfortunately this is rather cumbersome, as I have many Pyrex objects 
> which needs to be weakreferencable, and I need to subclass them all and 
> worry about constructing the right now. In addition, certain operations 
> in Pyrex seem to be capable of 'stripping off' the weakreferenceability 
> in a way I do not yet understand; I noticed that if I return an object 
> that was originally an Element and I declare its type to be ElementBase 
> there's a good chance that this object will not be weakreferenceable...
> 
> This complexity could all go away if Pyrex-defined extension objects 
> could be weakreferenceable from the start. It would simplify lxml a lot. 
> I'm fine with having to declare this somewhere, as long as it's possible.
> 
> What's the thinking on what this mechanism should look like in Pyrex?
> 
That would depend on whether or not weak referencing is available by
default. The thread did not include a final decision. If optional maybe:

cdef class C:
    cdef object weakref

Telling Pyrex to omit weak referencing when provided by default might
require some new syntax, a pragma keyword or something.

Lenard Lindstrom
<len-l at telus.net>





More information about the Pyrex mailing list