Background: I am using PyCharm 2019.1 and Python 3.7
Question: I would like to create a generic abstract class, such that when I inherit from it and set the generic type to a concrete type, I want the inherited methods to recognize the concrete type and show a warning if the types do not match.
Generic ABC with Subclass
from abc import ABC, abstractmethod
from typing import TypeVar, Generic
T = TypeVar("T")
class FooGenericAbstract(ABC, Generic[T]):
@abstractmethod
def func(self) -> T:
pass
class Foo(FooGenericAbstract[dict]): # I am specifying T as type dict
def func(self) -> dict: # I would like the return type to show a warning, if the type is incorrect
pass
No warning for incorrect type
I would expect an error here, since the return type list does not match the concrete type parameter dict.
class Foo(FooGenericAbstract[dict]): # I am specifying T as type dict
def func(self) -> list: # Should be a warning here!
pass