scratchattach icon indicating copy to clipboard operation
scratchattach copied to clipboard

Use dataclasses

Open faretek1 opened this issue 6 months ago • 9 comments

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

  • [x] ForumTopic

  • [x] ForumPost

  • [x] Classroom

  • [x] Session

  • [ ] PartialProject

  • [x] Comment

  • [ ] ReceivedRequest

  • [ ] CloudActivity

  • [x] User

  • [ ] BackpackAsset

  • [x] Studio

  • [x] Activity

faretek1 avatar May 30 '25 11:05 faretek1