Python ';类型';对象在函数定义处不可下标
我定义了这样一个函数Python ';类型';对象在函数定义处不可下标,python,python-3.x,dictionary,types,type-hinting,Python,Python 3.x,Dictionary,Types,Type Hinting,我定义了这样一个函数 def map_json_to_item_dictionary(json: dict[str, dict]) -> dict[int, Any]: result: dict[int, Any] = {} return result 但有一个例外,即“type”对象在函数定义处不可下标 PyCharm还提示异常类“type”未定义“\uuuu getitem\uuuuuu”,因此[]运算符不能用于其实例 看起来像python尝试从dict访问某些内容
def map_json_to_item_dictionary(json: dict[str, dict]) -> dict[int, Any]:
result: dict[int, Any] = {}
return result
但有一个例外,即“type”对象在函数定义处不可下标
PyCharm还提示异常类“type”未定义“\uuuu getitem\uuuuuu”,因此
[]运算符不能用于其实例
看起来像python尝试从dict
访问某些内容
我做错了什么?您需要从
键入模块导入Dict
和Any
:
from typing import Dict, Any
def map_json_to_item_dictionary(json: Dict[str, dict]) -> Dict[int, Any]:
result: Dict[int, Any] = {}
return result