Às 03:24 de 03/11/22, Paulo da Silva escreveu:
Hi!
And a typing problem again!!!
_______________________________________
class C:
def __init__(self):
self.__foos=5*[0]
@property
def foos(self) -> list[int]:
return self.__foos
@foos.setter
def foos(self,v: int):
self.__foos=[v for __i in self.__foos]
c=C()
c.foos=5
print(c.foos)
_______________________________________
mypy gives the following error:
error: Incompatible types in assignment (expression has type "int",
variable has type "List[int]")
How do I turn around this?
Changing def foos(self) -> list[int]: to
def foos(self) -> Union[list[int]]:
fixes the problem.
Not so elegant, however!
Regards.
Paulo
--
https://mail.python.org/mailman/listinfo/python-list