Or you could even just return an anonymous function, so it would look like:

    with grading_table.add_row(student_id) as add_grade:
        for grade in grades:
            add_grade(grade.component, grade.score)