◐ Shell
clean mode source ↗

Message 166142 - Python tracker

Richard, yes, I think that would work, I didn't think of using f.__self__'s type.
You might want to replace
  if self is not None and not isinstance(self, types.ModuleType):
with
  if self is not None and not isinstance(self, types.ModuleType) \
                      and not isinstance(self, type):
to correctly raise an exception when called on a classmethod too.