Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I tried to subclass threading.Condition earlier today but it didn't work out. Here is the output of the Python interpreter when I try to subclass the threading.Condition class:

>>> import threading >>> class ThisWontWork(threading.Condition): ...     pass ...  Traceback (most recent call last):   File "<stdin>", line 1, in <module> TypeError: Error when calling the metaclass bases     function() argument 1 must be code, not str 

Can someone explain this error? Thanks!

like image 206
David Underhill Avatar asked Feb 09 '10 18:02

David Underhill


1 Answers

You're getting that exception because, despite its class-like name, threading.Condition is a function, and you cannot subclass functions.

>>> type(threading.Condition) <type 'function'> 

This not-very-helpful error message has been raised on the Python bugtracker, but it has been marked "won't fix."

like image 139
Will McCutchen Avatar answered Sep 19 '22 07:09

Will McCutchen