On Thu, Jan 24, 2013 at 12:08:15PM -0800, Nils Bruin wrote:
> Ouch, yes that is a fundamental problem. What one should have is a
> custom `__new__` on UniqueRepresentation, with the python semantics,
> not the cython __cinit__ (formerly called and still accepted __new__).
> And there you can see the problem for how to arrange that properly in
> inheritance (let alone multiple inheritance!). In cython, the actual
> memory allocation happens on subclass level because it knows the full
> memory layout. superclasses only get to initialize that memory.
> However, the whole point of UniqueRepresentation is to avoid new
> allocation under select circumstances and return an old instance. In
> cython, a superclass fundamentally can't do that.
> 
> Instead, one would have to mandate creation via a factory function
> which can do the lookup (I guess metaclasses are just a way to
> formalize factory functions and incorporate them into inheritance). In
> the current cython programming model ensuring uniqueness cannot be
> done upon instantiation, because your earliest hook is `__cinit__`
> when the new instance already is allocated.

Shall we ask the Cython devs to implement the __classcall__ protocol?
Then we could merge the factory function and the class in Cython
classes as is done by UniqueRepresentation.

Cheers,
                                Nicolas
--
Nicolas M. ThiĆ©ry "Isil" <[email protected]>
http://Nicolas.Thiery.name/

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to