Skip to content

Using classmethods for constants #332

@huguesdevimeux

Description

@huguesdevimeux

I don't know if it would be a good idea, or if this has been already brought up (I think @leotrs mentioned a similar idea in #310 ).

The idea would be to change the way all the constants are implemented into something that would be similar to namespaces.
My idea would be, for example, for the colors, to do something like :

class Color : 
    ...
    @classmethod
    def red(self):
        return <color red>

Thus, one could access the red colour by simply doing Color.red() instead of the ugly RED

Similar reasoning could be applied for every item within constants.py. So we would have, for example, Message.not_setting_font().
We could even go further, by implementing all constants utils within these classes. (for example, utils.interpolate_color)

A major advantage would be that everything would be much better organized and more, I think, clean. The constants would be well arranged by classes (and so we could get auto-completion ;D), On the other hand, it would be a little bit more long to use, as you would have to access to Color every time.

NOTE : I took inspiration on how colors are implemented on the discord python API, but I can"'t find a link to the file :/

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorRefactor or redesign of existing code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions