2

Just playin around class

def func(*args, **kwargs):
    print args, kwargs

class Klass(func): pass

it throws error

TypeError: Error when calling the metaclass bases function() argument 1 must be code, not str

What does it mean, i am passing no str nowhere? and yes I should be passing class in bases but why didn't error say that, instead of this cryptic error?

4
  • The title and most of the question suggests you don't understand why this is happening, but you're really asking why didn't the error message have different text. Commented Feb 22, 2010 at 5:35
  • yes I do not understand why it throws such cryptic error, instead of saying "functions can not be class base", i want to know why it is thorwing such cryptic error Commented Feb 22, 2010 at 5:40
  • Python throws all kinds of cruddy errors! Commented Feb 22, 2010 at 5:50
  • Python3.1 has made the message even less helpful TypeError: function() argument 1 must be code, not str Commented Feb 22, 2010 at 6:18

1 Answer 1

2

see here for the reason for the cryptic msg

http://bugs.python.org/issue6829

questions Error when calling the metaclass bases: function() argument 1 must be code, not str has same problem.

Edit: play-around

Though you can use metaclass to make it work in a twisted way ;)

def func(name, klassDict):
    return type(name, (), klassDict)

class MyMeta(type):
    def __new__(self, name, bases, klassDict):
        return bases[0](name, klassDict)

class Klass(func):
    __metaclass__ = MyMeta

print Klass
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.