Using classmethods for constants
See original GitHub issueI 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 😕
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Yes, that’s also what I proposed doing (enum for colors) However, can we please switch to colors with ints? Strings require parsing. Let’s delegate that job to Python
so your example would be
Yes it should! I was just making sure I understood correctly. Also, can you please open a new issue for that? This one has ran its course.