`Iterator[int]` not recognised as `Hashable`
还没有人认领这个 Issue。
评估
调研方向
从链接的 mypy playground 中的 main.py 复现程序开始,运行 mypy 以确认无效索引类型诊断。跟踪 Iterator[int] 如何针对 Hashable 进行检查,然后验证复现程序没有错误,同时保留预期的元组索引类型。
由索引模型根据 Issue 内容生成。
描述
Bug Report
Iterator[int] is not recognised as Hashable.
To Reproduce
- https://play.ty.dev/13380319-febd-421a-9540-ce987c4bbc9c
- https://pyrefly.org/sandbox/?project=v2.lVVBboMwEPzKqjlgWoJL1RMPqHrs3eWAUgSWmoCwqZJD_95Zg8GoSZRckGV21-uZ2fEdlvnoBcqlxTEH_NbrZdLKkZ4o47DAk4QLf32JQcp_zDb0MW7QdDzcAmDXAzwJIKafhw3sqKLG2s7kUvr0tq9ldZBf7c7IVYYklkf5U2rndOty1DqODcqeJyu7iaxo5Cq6RlXETCFirw0Grd6aoav67Q4iwk8LWQKLBXHtIb9g3Mvz8V6ahi-2-Bmb4FuP0Vk5mqksTwJMbe1bCaHNnOwAC1TmW4c1i9n7_HkKHAMHTl5mmdIUADIz-1N3IlwCShmHJqGJILeLta4b9nOetLlPEadhf8J1Ibg0HtL5Gyc83L1Qz0WMtcoKCCioofIgoACoiIDCLotdP_z-AQ
- https://pyright-play.net/?code=GYJw9gtgBAxmA28CmMAuBLMA7AzgOgEMAjGKdCABzBFSgGUkBHAVySxiQBooAJAnABbFkAKBEx4-HFAAiBVAQBiIAhCQAuEVG1QAJkmBQA%2BkZxIMqJBBMAKLTodn4wbgGskAT3VRUzCsgBtHHh0Dm4%2BQWEkAF1uADcCeFZvBhY2DgD0LFRo%2B20ASigAWgA%2BKAA5bA0oPFqxAGIoCA8KDygCLF0fNqQQcBBuVpADeDaOrqH0AHMBWgopETkFZVUkG3y8EzMLK1sbYNC1yqwuCqruY6R87nRLEBsAgAZo-OuoAIBGF8X5JRU1dYBdQ3O4PZ75aJQAC87y%2BIiAA
- https://mypy-play.net/?gist=71aba787eb6f23212e1fd4e0a63cf86f
from collections.abc import Sequence, Hashable
class DataFrame:
def __setitem__(
self, key: tuple[slice, Hashable], value: Sequence[int]
) -> None: ...
# mypy and ty error, pyrefly and pyright pass
DataFrame().__setitem__((slice(None, None, None), iter([0])), [1])
DataFrame()[:, iter([0])] = [1]
Expected Behavior
error free
Actual Behavior
main.py:9: error: Invalid index type "tuple[slice[Any, Any, Any], Iterator[int]]" for "DataFrame"; expected type "tuple[slice[Any, Any, Any], Hashable]" [index]
main.py:10: error: Invalid index type "tuple[slice[None, None, None], Iterator[int]]" for "DataFrame"; expected type "tuple[slice[Any, Any, Any], Hashable]" [index]
Found 2 errors in 1 file (checked 1 source file)
Your Environment
Playground
- 主要语言
- Python
- 星标
- 20.6k
- 派生
- 3.3k
- 平均合并
- 1 天 12 小时
- 30 天内合并 PR
- 58
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/mypy 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
-
documentation
难度 2/5 1-3 小时 新手友好度 72/100
-
bug topic-configuration topic-error-reporting
难度 2/5 1-3 小时 新手友好度 68/100
-
bug topic-attrs
难度 2/5 1-3 小时 新手友好度 62/100
相似的 Issue
-
essnmx good first issue
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 65/100
syfoud/Simulated_Scepter#174 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Giskard-AI/giskard-oss#2840 · 1 条评论 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success 未关闭area: repo bug perceived difficulty: 2
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
yeti-platform/yeti#1380 ·