-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Using classmethods for constants #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I agree with your proposal in general. Three points I want to make.
|
An enum might be useful for colors: from enum import Enum
class Colors(Enum):
white = "#000000"
black = "#FFFFFF"
...
## use Colors.<color>.value internally
print(Colors.white.value) ## "#000000" |
Yes, that's also what I proposed doing (enum for colors) so your example would be from enum import Enum
class Colors(Enum):
white = 0x000000
black = 0xFFFFFF
...
## use Colors.<color>.value internally
print(Colors.white.value) ## 0x000000 |
Yeah, this is what class attributes are for; note that attrs allows for this without overlapping with the user-specified attrs by using the
deprecate and remove imo; one thing that is annoying about how it currently is is how intellisense works kinda badly with it - using a class would make it work better
we could add a color parser which accepts multiple types of values, but yeah this is the wrong issue i guess |
So what I gather from this discussion is the following:
I think this issue pertains (1). The other two should be separate issues IMO. |
Can I put in a word for having colour be a synonym of color? |
You mean alias every instance of |
Is that not doable? |
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. |
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 :
Thus, one could access the red colour by simply doing
Color.red()
instead of the uglyRED
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 :/
The text was updated successfully, but these errors were encountered: