typing: property/setter and lists?

Paulo da Silva p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt
Wed Nov 2 23:24:19 EDT 2022


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?

Thanks.
Paulo



More information about the Python-list mailing list