On Fri, Mar 13, 2009 at 10:11 AM, Lisandro Dalcin <[email protected]> wrote:
> On Fri, Mar 13, 2009 at 2:39 PM, Stefan Behnel <[email protected]> wrote:
>> So, can't we just require that ExtType.__new__() returns an instance of
>> ExtType (or its subtypes)?
>
> As a first approach, it could be like that...
>
> ? Or is there a use case that would benefit from
>> returning arbitrary things?
>>
>
> Well, Python supports this, we could in case it is possible....

How about this?  In the hypothetical future version of Cython that
allows overriding __new__, say that the overrides have to be declared
in the .pxd file, with

  cdef TYPE __new__(self, foo, bar)

(where TYPE defaults to the class being declared, if omitted).  So
when generating code, if the class doesn't override __new__, you know
that calling the class returns an instance; if the class does override
__new__, then the return type is explicitly given.  This could be a
parent class, for my use case where I want to return an instance of a
sibling class; or it could be "object", if anybody ever has a use case
for having __new__ return an arbitrary object.

Carl
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to