By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

style question: anything wrong with super(type(self), self).f() ?

P: n/a
Is there anything wrong with using something like super(type(self),
self).f() to avoid having to hardcode a type? For example:

class A(object):
def f(self):
print "in A.f()"

class B(A):
def f(self):
super(type(self), self).f()

obj = A()
obj.f() # prints "in A.f()"
By "wrong" I mean, is there any reason why this is just a Bad Idea?
Seems helpful to me, if I change the name of the 'B' class, I don't
have to change super() calls as well.

--
Adam Monsen
http://adammonsen.com/

Sep 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Mon, 19 Sep 2005, Adam Monsen wrote:
Is there anything wrong with using something like super(type(self),
self).f() to avoid having to hardcode a type?
What happens when that method gets called by an overriding method in a
derived class?
For example:

class A(object):
def f(self):
print "in A.f()"

class B(A):
def f(self):
super(type(self), self).f()

obj = A()
obj.f() # prints "in A.f()"
Continuing your example:

class C(B):
def f(self):
super(type(self), self).f()

obj = C()
obj.f()

Think about what's going to happen. Then try it!
By "wrong" I mean, is there any reason why this is just a Bad Idea?
That rather depends if the behaviour i demonstrate above is useful to you.

:)
Seems helpful to me, if I change the name of the 'B' class, I don't have
to change super() calls as well.


It would indeed be very useful.

tom

--
buy plastic owl
Sep 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.