Skip to content

Parse Nested Objects #56

Open
Open
@liblit

Description

@liblit

Original title was "Canvas.get_assignment_group should turn assignments into Assignment instances"

A call to Course.get_assignment_group can optionally include full details about the assignments in the group. That is a nice way to reduce round-trips if we already know that the details will be needed.

In version 0.6.0 of canvasapi, these assignment details are provided as a list of dict.

group = course.get_assignment_group(group.id, include='assignments')
for assignment in group.assignments:
    print(assignment)  # prints each assignment as a dict

I was expecting them to be a list of Assignment instances. Each dict seemingly has all of the details needed to build an Assignment, and I can do that conversion myself:

group = course.get_assignment_group(group.id, include='assignments')
assignments = [Assignment(group._requester, raw) for raw in group.assignments]
for assignment in assignments:
    print(assignment)  # prints each assignment as an Assignment

However, accessing group._requester directly seems like cheating. And I would have expected canvasapi to take care of such details behind the scenes. Can that be done? Can Course.get_assignment_group convert each dict into a proper Assignment for me? (Obviously it should only do so if assignment details are present; without include='assignments', no details are given, so there is nothing to convert.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions