How to get class variables and type hints?

typing.get_type_hints is another method that doesn’t involve accessing magic properties directly:

from typing import get_type_hints

class Person:
    name: str
    age: int

get_type_hints(Person)
# returns {'name': <class 'str'>, 'age': <class 'int'>}

Leave a Comment

tech