So, I have one dataclass as follows
@dataclass
class DataObj:
""" DataObj creates an object for each record in data
"""
name: str
profit: int
space: float
I have another container class that holds the objects of above class
class DataContainer:
""" Data Container class holding objects of DataObj class
"""
def __init__(self, data_tuple_list: List[Tuple[str, int, float]]) -> None:
self.container = []
for data_tuple in data_tuple_list:
self.container.append(DataObj(*data_tuple))
def __getitem__(self, n: int) -> Type[DataObj]:
return self.container.__getitem__(n)
However, when I check the code using mypy, I get following error
error: Incompatible return value type (got "DataObj", expected "Type[DataObj]")
Found 1 error in 1 file (checked 1 source file)
My python version is 3.8.10.
Question: How to fix the error.
EDIT
- If I use
self.container: List[DataObj] = [], I geterror: Incompatible return value type (got "DataObj", expected "Type[DataObj]") Found 1 error in 1 file (checked 1 source file) - If I use
self.container: List[Type[DataObj]] = [], I geterror: Argument 1 to "append" of "list" has incompatible type "DataObj"; expected "Type[DataObj]" Found 1 error in 1 file (checked 1 source file).