Unexpected type checking with pyright

未关闭
#94 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
1-2 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
python
领域
testing-qa

调研方向

Start by reproducing the reported pyright behavior with the issue’s code sample and inspect the library’s type annotations for ElectricPotentialArray, Power, and tu.V. The issue does not name a source file or test; trace how indexing is typed and add a focused regression check. Done means the invalid x[tu.V] expression is reported as a type error.

由索引模型根据 Issue 内容生成。

描述

Using pyright in neovim, I see unexpected behavior in type checking:

import tunits as tu

x = (tu.ElectricPotentialArray(np.array([1, 2, 3]) * tu.V), 5 * tu.W)
reveal_type(x)  # Type of "x" is "tuple[ElectricPotentialArray, Power]"
y = x[tu.V]
reveal_type(y)  # Type of "y" is "ElectricPotentialArray | Power"

The third line should be flagged as a type error. From the fourth line, it looks like tu.V is being treated as an integer. Is it possible that the type annotations for this library have some bug?

主要语言
Python
星标
10
派生
8
平均合并
5 分钟
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

quantumlib/TypedUnits 的其他 Issue

查看 quantumlib/TypedUnits 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。