调用元类基时出错:function() 参数 1 必须是代码,而不是 str [英] Error when calling the metaclass bases: function() argument 1 must be code, not str
问题描述
我今天早些时候尝试将 threading.Condition 子类化,但没有成功.这是我尝试子类化 threading.Condition 类时 Python 解释器的输出:
<预><代码>>>>进口螺纹>>>类 ThisWontWork(threading.Condition):... 经过...回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中TypeError:调用元类基类时出错function() 参数 1 必须是代码,而不是 str有人可以解释这个错误吗?谢谢!
你得到这个异常是因为,尽管它的名字类似于类,threading.Condition
是一个函数,你不能子类化功能.
这个不太有用的错误消息已经在 Python 错误跟踪器上提出,但它已经标记为无法修复."
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!
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."
这篇关于调用元类基时出错:function() 参数 1 必须是代码,而不是 str的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!