I've got a dataclass with attributes of various types:
@dataclass
class Student:
__slots__ = ['name', 'age', 'height', 'present', etc...]
name: str
age: int
grade: float
present: bool
etc...
class Classroom():
tree: xml element object
roster = []
def get_roster():
for s in self.tree.find('students'):
student = Student('', 0, 0.0, False, etc...)
for attr in student.__slots__:
attrEntry = s.find(attr)
if attr is not None:
value = attrEntry.get('value') # How to convert value into appropriate type according to type annotation?
setattr(student, attr, value)
roster.append(student)
How can I apply the correct type conversion according to the type hint?