python - 调用元类库时出错 : function() argument 1 must be code, not str

标签 python class inheritance metaclass

我今天早些时候尝试对 threading.Condition 进行子类化,但没有成功。这是我尝试继承 threading.Condition 类时 Python 解释器的输出:

>>> 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

有人可以解释这个错误吗?谢谢!

最佳答案

你得到这个异常是因为,尽管它的名字类似于类,threading.Condition 是一个函数,你不能子类化函数。

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

这个不太有用的错误消息是 raised on the Python bugtracker ,但它已被标记为“不会修复”。

关于python - 调用元类库时出错 : function() argument 1 must be code, not str,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2231427/

相关文章:

c# - 抽象类和接口(interface)中可以使用相同的字段名称吗?

c# - 显式地将基类转换为派生类

python - 类属性的类型提示

python - 与俄语/西里尔文新闻文章的永久链接

python - 用另一个 numpy 数组索引 numpy 数组

android - NoClassDefoundError while class is exist in the program

node.js - 将 sequelize 模型实例传递给服务在 express.js 中不起作用

java - 为什么 java.io.Serializable 不是一个类?

c++ - ';' token 之前的预期类型说明符

python - 如何从 python 控制 MT4?