I can do this to define a Matrix type for instance:
from typing import List
Matrix = List[List[float]]
How can I do the same with custom types? For instance I tried this but it doesn't seem effective:
class MyClass:
@staticmethod
def __getitem__(self, item: Type):
"""
You can type like this:
var: MyClass[BaseCausalityFeature] = something
"""
return MyClass
Moreover, what I've just coded doesn't work when I try to use it, it says Class 'type' does not define '__getitem__', so the '[]' operator cannot be used on its instances
.
I'd love to be able to specify custom nested types to my custom objects with typings, like CPP templates to make my code more readable in presence of complex type hierarchies and composition.
I'm using Python 3.6.9
.