Terry Reedy wrote:
But if classmethods are intended to provide alternate constructors

But I do not remember that being given as a reason for classmethod(). But I am not sure what was.

Well I haven't searched thoroughly, but I know one place that it's referenced is in descrintro[1]:


"Factoid: __new__ is a static method, not a class method. I initially thought it would have to be a class method, and that's why I added the classmethod primitive. Unfortunately, with class methods, upcalls don't work right in this case, so I had to make it a static method with an explicit class as its first argument. Ironically, there are now no known uses for class methods in the Python distribution (other than in the test suite). However, class methods are still useful in other places, for example, to program inheritable alternate constructors."

Not sure if this is the only reason though, and even if it is, it might not be entirely applicable because while the itertools functions may be supplying alternate constructors, it's not clear why anyone would subclass iter[2], so the constructors aren't likely to be inherited.

STeVe

[1] http://www.python.org/2.2.3/descrintro.html#__new__
[2] That is, in the simple case, where iter is still basically a factory function, not a type wrapper.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to