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

无法通过numpy.typing.mypy_plugin复现NBitBase示例的类型推断结果

numpy.typing.mypy_plugin类型推断与官方文档预期不符

问题描述

使用numpy.typing.mypy_plugin时,按照官方文档中NBitBase的示例代码执行后,mypy输出的类型推断结果与预期不一致。

预期行为

根据官方文档,mypy应输出如下类型信息:

# note: Revealed local types are:
# note:     a: numpy.floating[numpy.typing._16Bit*]
# note:     b: numpy.signedinteger[numpy._typing._64Bit*]
# note:     out: numpy.floating[numpy.typing._64Bit*]

实际行为

运行mypy后得到的实际输出:

╭sam@sam-XPS-15-7590:2 ...mpy_mypy_plugin_not_working ❖ do 16 10:19 
╰[poetry: numpy_mypy_plugin_not_working/.venv]$ mypy
src/example/__init__.py:22: note: Revealed local types are:
src/example/__init__.py:22: note:     a: numpy.floating[numpy._typing._16Bit]
src/example/__init__.py:22: note:     b: numpy.signedinteger[numpy._typing._64Bit]
src/example/__init__.py:22: note:     out: numpy.floating[Union[numpy._typing._16Bit, numpy._typing._64Bit]]

最小可复现示例(MWE)

已准备包含src/example/__init__.py代码、pyproject.toml配置的最小复现环境,可通过poetry install创建相同版本的虚拟环境。

已尝试的操作

  • 验证Python和mypy可执行文件路径正确;
  • 确认mypy已正确加载numpy.typing.mypy_plugin;
  • 禁用插件后,mypy输出仍与错误结果一致。

内容的提问来源于stack exchange,提问作者Sam De Meyer

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 01:02:45