Let's suppose to have a class Bag that contains a list of item.
What we know about item is just that it has a method called : printDescription().
Now I want to define a method printAllItemsDescription inside Bag, that invokes the method printDescription() on each item inside items list.
This should be the code (it's wrong but I think should looks like this) :
class Bag:
items:list[item] = []
.
.
.
def printAllItemsDescription(this):
for item in this.items:
item.printDescription()
My problem is that I don't know how to tell python that my items is a list of item.
I know I can do something like item:Item but don't know how to do it with lists.
Then while iterating on items it will know that each item contains a method called printDescription(), but on this moment item is just a variable of undefined type.
P.S. : I tried also to do something like x:list[item] but I got this error :
Subscript for class "list" will generate runtime exception; enclose type annotation in quotes