Skip to content

Use dataclasses #408

Closed
Closed

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

Activity

  1. added
    enhancement
    on May 30, 2025
  2. TheCommCraft commented on Jun 3, 2025

    @TheCommCraft
    Collaborator

    I changed it for ForumTopic

  3. TheCommCraft commented on Jun 4, 2025

    @TheCommCraft
    Collaborator

    Now also for ForumPost

  4. faretek1 commented on Jun 7, 2025

    @faretek1
    CollaboratorAuthor

    Now also for Classroom

  5. faretek1 commented on Jun 7, 2025

    @faretek1
    CollaboratorAuthor

    Warning

    Now also for Session

  6. faretek1 commented on Jun 7, 2025

    @faretek1
    CollaboratorAuthor

    dataclasses with inheritance would cause problems if some of the attributes are non-default
    https://medium.com/@aniscampos/python-dataclass-inheritance-finally-686eaf60fbb5
    Either we could use kw_only, or we could just make everything have default values.
    This concerns PartialProject and Project

  7. TheCommCraft commented on Aug 4, 2025

    @TheCommCraft
    Collaborator

    Now for User

  8. faretek1 commented on Aug 5, 2025

    @faretek1
    CollaboratorAuthor

    🔥

  9. faretek1 commented on Sep 20, 2025

    @faretek1
    CollaboratorAuthor

    i will try to do comment now


    done in 10ed59c

  10. faretek1 commented on Oct 11, 2025

    @faretek1
    CollaboratorAuthor

    doing studio

  11. TheCommCraft commented on Feb 6, 2026

    @TheCommCraft
    Collaborator

    Now, only BackpackAsset is left.

  12. faretek1 commented on May 3, 2026

    @faretek1
    CollaboratorAuthor

    i did backpackasset finally

  13. added a commit that references this issue on May 7, 2026
    2ba037d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions