Код: Выделить всё
from abc import ABC, abstractmethod
from typing import Type, TypeVar, Dict
class Interface(ABC):
@abstractmethod
def method(self):
pass
class Implementation(Interface):
pass
T = TypeVar("T", covariant=True)
def get_implementation(interface: Type[T], *args, **kwargs) -> T:
dictionary: Dict[Type[T], T] = {Interface: Implementation}
return dictionary[interface](*args, **kwargs)
implementation = get_implementation(Interface)
Код: Выделить всё
main.py:15: error: Dict entry 0 has incompatible type "Type[Interface]": "Type[Implementation]"; expected "Type[T]": "T"
main.py:16: error: "object" not callable
main.py:19: error: Only concrete class can be given where "Type[Interface]" is expected
Подробнее здесь: https://stackoverflow.com/questions/760 ... interfaces