Determining what superclass supplies a method in PythonIt turns out that there are some situations in Python where it is useful to
know what your superclass is. In particular, it
would be nice for mixin classes to be able to know when they are about
to call methods on It would be nice if the objects returned by
def getsuper(kls, rkls):
mro = rkls.__mro__
i = list(mro).index(kls)
return mro[i+1]
def getprovider(so, meth):
s = getsuper(so.__thisclass__,
so.__self_class__)
r = getattr(s, meth)
if hasattr(r, "im_class"):
return r.im_class
elif hasattr(r, "__objclass__"):
return r.__objclass__
else:
return None
The (Python is sometimes irritatingly inconsistent about this sort of
introspection, so I am probably still missing some special cases.
I believe that any return of |
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |