python - dict 的类型提示给出 TypeError: 'type' object is not subscriptable
问题描述
memo: dict[int, int] = {0: 0, 1: 1} # *our base cases*
返回以下错误:
TypeError: 'type' object is not subscriptable
解决方案
我想你应该使用Dict
,例如:
from typing import Dict
memo: Dict[int, int] = {0: 0, 1: 1}
在您的情况下,您使用dict
的是 which 类型type
>>> type(dict)
<class 'type'>
>>> type(Dict)
<class 'typing._GenericAlias'>
推荐阅读
- kubernetes - kube-apiserver 没有使用 docker-dns
- mysql - SQL 命令用于从具有 4 列的表中写入和读取所有值
- azure-blob-storage - 在 Azure Blob 存储中更新 Blob 需要多长时间?
- google-sheets - 将给定列的每日运行计数制表的公式
- ruby-on-rails - 如何使用rails中数组内的哈希查询json数据?
- azure - 未知对等 xxx,不包括模式协议检查
- azure - Azure 数据资源管理器:多选参数“全选”返回所有可能的选项
- c++ - 直接从嵌套循环内部移动到外部循环的下一次迭代
- python - 增强分配操作何时表现为就地操作,何时不表现为?
- scala - 如何在 Slick 中表达窗口功能?