Is there a way to get the field type of a class in Python, for use as a type annotation?
import dataclasses
@dataclasses.dataclass
class A:
field: str
def main() -> None:
value: A.field = 123 # Want mypy to flag an error here
Where A.field
is meant to refer to the type str
, the type of A.field
.
I'd like to do this to capture errors earlier for variables that may eventually be assigned to fields.