Для следующего кодаTyping: несовместимый тип, когда объявляют typing.Type []
# -*- 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 возвращают следующие ошибки (питон 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
в качестве ключей Dict. Как объявить тип?
@JacquesGaudin OP использует модуль '' mypy' (http://mypy.readthedocs.io/en/latest/basics.html) для проверки типа. Это приводит к ошибке. –
@RickTeachey Спасибо, я этого не осознавал. –