I'm interested to know the type of an empty collection considering that I used type hints.
For instance, given the following:
from dataclasses import dataclass, field
@dataclass
class A:
x : list[int] = field(default_factory=list)
a = A()
t = a.__dataclass_fields__['x'].type
then t
is list[int]
, and what I would like to know is how to get the type int
from t
?
I could parse t
to a string and then regex extract the type as list[<type>]
, but is there a more standard way?