How can I declare an array (or at least list) in @dataclass
? A something like below:
from dataclasses import dataclass
@dataclass
class Test():
my_array: Array[ChildType]
There is no Array
datatype, but you can specify the type of my_array
to be typing.List
:
from dataclasses import dataclass
from typing import List
@dataclass
class Test:
my_array: List[ChildType]
And from Python 3.9 onwards, you can conveniently just use list
:
from dataclasses import dataclass
@dataclass
class Test:
my_array: list[ChildType]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With