对于以下代码
# -*- coding: utf-8 -*-
import typing
class A(object):
pass
class B(A):
pass
class C(A):
pass
class D(A):
pass
class E(A):
pass
MAPPING_X = {
B: 'b',
C: 'c',
}
MAPPING_Y = {
D: 'd',
E: 'e',
}
all_mappings = {} # type: typing.Dict[typing.Type[A], str]
all_mappings.update(MAPPING_X)
all_mappings.update(MAPPING_Y)
mypy 返回以下错误(python 3.4):
t.py:30: error: Argument 1 to "update" of "dict" has incompatible type Dict[type, str]; expected Mapping[Type[A], str]
t.py:31: error: Argument 1 to "update" of "dict" has incompatible type Dict[type, str]; expected Mapping[Type[A], str]
我不明白如何指定我想要的子类A
作为字典键。如何声明类型?