Why are so many built-in types inheritable?

Fabiano Sidler fabianosidler at gmail.com
Sat Mar 25 16:22:13 EST 2006


Kent Johnson <kent at kentsjohnson.com> wrote:
> You could do this with a simple decorator:
> http://wiki.python.org/moin/PythonDecoratorLibrary#head-d4ce77c6d6e75aad25baf982f6fec0ff4b3653f4
>
> or I think your class PrintingFunction would work as
> class PrintingFunction(object):
>    def __init__(self, func):
>      self.func = func
>    def __call__(self, *args, **kwargs):
>      print args, kwargs
>      return self.func(*args, **kwargs)

The problem with this is that the func_code attribute would contain
the code of PrintingFunction instead of func. What I wanted to do, is
to keep the original behaviour, i.e. set the variable __metaclass__ to
DebugMeta and so get debug output, without changing a function and
getting the original function's code object by the func_code
attribute, not PrintigFunction's one. That's why I *must* inherit from
<type 'function'>.

Greetings,
F. Sidler



More information about the Python-list mailing list