Specify object type in definition list input

Viewed 26

In a function, I want to specify the object type inside the list I have as input. In particular, I would like to require that all the elements type of that list (the one I have as input) are the one of the objet I have previously defined.

What I have tried is this (the function is inside a class).

def testInput(self,listType1:list[int],listType1:list[bool],listType3:list[<my_object>]) -> None:
  pass

The error that occours is the following.

TypeError: 'type' object is not subscriptable

Is there a way to obtain what I want?

source: https://docs.python.org/3/library/typing.html

0 Answers
Related