I created a class with a list attribute containing an int and a float. I then tried creating a getter method to return the list as a tuple.
from typing import Tuple, List
class MyClass:
def __init__(self):
self.__lst = [3, 5.0]
def get_lst_as_tup(self) -> Tuple[int, float]:
return tuple(self.__lst)
while it seems to work properly, PyCharm presents a problem:
Expected type 'Tuple[int, float]', got 'Tuple[Union[int, float], ...]' instead
after seeking stack overflow I tried several other implementations for the return statement. that resulted in the same error:
return (element for element in self.__lst)
return tuple(element for element in self.__lst)
return (*self.__lst,) this specific implementation resulted in :
Expected type 'Tuple[int, float]', got 'Tuple[Any]' instead
I was able to get rid of the error by using return self.__lst[0], self.__lst[1]
but I do not understand why it does not accept the other implementations.
Notes: I did not use the word tuple elsewhere in the file. This error occures even when this is all there is in the file.