当我对容器进行子类化时,如何为我的定义的容器部分指定类型提示?我的意思是类似于(目前不支持)以下内容:
from typing import Dict
class MyDict(dict: Dict[str, int]):
def __init__(...):
...
这样,当我尝试通过继承自基类的接口添加,删除等对象到我的dict时,可以对其进行类型检查。
它的形式提到了here
from typing import Dict
class Test(Dict[str, int]):
def __init__(self):
self.update({'a': 5})
test = Test()
print(test) # prints {'a': 5}