Can __iter__ be used as a classmethod?
Greg Chapman
glc at well.com
Thu Mar 6 09:52:00 EST 2003
On Tue, 4 Mar 2003 23:21:16 +0100, "Samuele Pedroni" <pedronis at bluewin.ch>
wrote:
>It is worth to notice that once you override one of them (like g in D
>overriding g in C) it is impossible to call in a clean way the parent
>version (C g) passing the derived class (D), which is what would happen in
>case of no overriding (if D would not define g, then D.g() would call g in C
>passing D), (so above C.g() obviously is calling g in C passing C). "Let's
>call this their price".
>
This works for me with 2.22 and 2.3a2:
class C(object):
def g(cls):
print 'C', cls
g = classmethod(g)
class D(C):
def g(cls):
print 'D', cls
super(D, cls).g()
g = classmethod(g)
Both D.g() and D().g() print:
D <class '__main__.D'>
C <class '__main__.D'>
Am I missing some subtlety here?
---
Greg Chapman
More information about the Python-list
mailing list