I've fixed classmethod issue patch is in trac.
2010/11/3 mark florisson <[email protected]>: > err, that should be super(TheClass, cls), otherwise you make your class > unsubclassable. > > On 3 November 2010 10:34, mark florisson <[email protected]> wrote: >> >> >> On 3 November 2010 07:15, Robert Bradshaw <[email protected]> >> wrote: >>> >>> On Tue, Nov 2, 2010 at 10:59 PM, Stefan Behnel <[email protected]> >>> wrote: >>> > Robert Bradshaw, 02.11.2010 23:21: >>> >> On Tue, Nov 2, 2010 at 3:11 PM, Vitja Makarov wrote: >>> >>> http://docs.python.org/reference/datamodel.html#basic-customization >>> >>> >>> >>> """Called to create a new instance of class cls. __new__() is a >>> >>> static >>> >>> method (special-cased so you need not declare it as such) that takes >>> >>> the class of which an instance was requested as its first argument. >>> >>> The remaining arguments are those passed to the object constructor >>> >>> expression (the call to the class). The return value of __new__() >>> >>> should be the new object instance (usually an instance of cls).""" >>> >> >>> >> I was actually thinking about cdef classes, where __new__ is much more >>> >> subtle. I didn't realize it was a static method that takes the class >>> >> as a first argument rather than just a class method. >>> > >>> > It needs to be to support inheritance. You usually call the __new__ >>> > method >>> > of the superclass to create the instance that you return. So you must >>> > be >>> > able to pass the required class through the hierarchy explicitly. >>> >>> Good point, I hadn't thought about that. >>> >>> - Robert >>> _______________________________________________ >>> Cython-dev mailing list >>> [email protected] >>> http://codespeak.net/mailman/listinfo/cython-dev >> >> It could also work with a classmethod, because you'd be using super(cls, >> cls).__new__(), which also ensures that the subclass is passed as the first >> argument to __new__ in superclasses. Of course, type(TheClass).__call__ will >> pass the TheClass as the first argument, so if you make __new__ a >> classmethod it will need to take the class as two arguments. > > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev > > _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
