You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cython v3.0.0a11是否存在子类型多态性失效问题?

Cython v3.0.0a11派生类传参类型错误问题

在Cython v3.0.0a11版本中,将继承自内置类型(如int)的派生类实例传递给声明接受基类类型参数的函数时,会触发类型不匹配错误,该问题在v0.29.32稳定版本中不存在。

复现代码

test.pyx

class MyInt(int):
    pass

def takes_int(a: int):
    pass

try.py

from test import takes_int, MyInt

takes_int(MyInt(1))

错误输出

运行try.py后会抛出以下错误:

Traceback (most recent call last):
  File "C:\Users\LENOVO PC\PycharmProjects\MyProject\cython_src\try.py", line 3, in <module>
    takes_int(MyInt(1))
TypeError: Argument 'a' has incorrect type (expected int, got MyInt)

临时解决方法

切换至Cython v0.29.32版本,清理之前生成的C文件和目标文件后重新编译运行,即可消除该错误。这是Cython 3.0 alpha版本在类型检查逻辑变更后出现的兼容性问题,后续正式版本大概率会修复该问题。

内容的提问来源于stack exchange,提问作者Alian713

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 23:50:29