A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-March/062334.html below:

[Python-Dev] Why are so many built-in types inheritable?

[Python-Dev] Why are so many built-in types inheritable?Fabiano Sidler fabianosidler at gmail.com
Mon Mar 13 21:29:06 CET 2006
Hi folks!

Let me explain the above question:
For debugging purpose I tried this:

--- snip ---
def foo(): pass
function = type(foo)

class PrintingFunction(function):
  def __init__(self, func):
    self.func = func
  def __call__(self, *args, **kwargs):
    print args, kwargs
    return function.__call__(self, args, kwargs)

class DebugMeta(type):
  def __new__(self, name, bases, dict):
    for name in dict:
      if type(dict[name]) is function:
        dict[name] = PrintingFunction(dict[name])

--- snap ---

Now I tought I were able to let all methods of classes with DebugMeta
as metaclass print out their arguments.  But I got the following sad
error:

TypeError: Error when calling the metaclass bases
    type 'function' is not an acceptable base type

That's a pity, isn't it?
What could I do to get the above code to work? (No, I don't want to
reimplement <type 'function'> without this unpleasant behaviour in
Python.

Greetings,
F. Sidler
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4