Skip to content

Use dataclasses #408

@faretek1

Description

@faretek1

Currently, when working on scratchattach, code completion is a problem. Sometimes, misremembering the name of an attribute can cause issues - e.g. setting Session.session_id instead of Session.id. This could be partially solved/easily checked if there is good code completion available. This is the problem addressed in #381

As a solution to the code completion issue regarding many object attributes and to improved readability, using dataclasses could be a good idea. This is one of the alternatives listed in #381, and is probably the easiest and cleanest way of doing so.

Notes:

  • any processing upon initialisation is to move to the __post_init__ method

  • using self.__dict__.update(**entries) could be partially replaced by cls(**entries) - this will cause errors for unrecognised attribute names, which is a good thing

  • These would be quite large changes so testing might be necessary

  • dataclasses' built-in repr() functionality might be better for use compared to some existing __repr__ methods. However, if one is to use this, a lot of field(repr=False, ...) may be necessary

  • ForumTopic

  • ForumPost

  • Classroom

  • Session

  • PartialProject

  • Comment

  • ReceivedRequest

  • CloudActivity

  • User

  • BackpackAsset

  • Studio

  • Activity

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions