Skip to content

Do we really need to add every color to locals()? #81

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

Closed
leotrs opened this issue May 25, 2020 · 5 comments
Closed

Do we really need to add every color to locals()? #81

leotrs opened this issue May 25, 2020 · 5 comments
Labels
pr:deprecation Deprecation, or removal of deprecated code refactor Refactor or redesign of existing code

Comments

@leotrs
Copy link
Contributor

leotrs commented May 25, 2020

Currently, constants.py is adding every color inside COLOR_MAP to the locals() dictionary. This is usually frowned upon in Python in general.

If we want to keep exposing all colors to the end user without any namespace access (like manim.colors.RED or some such), then we can carefully import all colors inside __init__.py. This could be done for the purpose of backward compatibility.

@PgBiel PgBiel added pr:deprecation Deprecation, or removal of deprecated code refactor Refactor or redesign of existing code labels May 25, 2020
@leotrs
Copy link
Contributor Author

leotrs commented May 27, 2020

I would love some feedback here.

I think the only problem with removing all colors from locals() is that this could be a breaking change for some users. Maybe we could deprecate it before removing them completely.

@PgBiel
Copy link
Member

PgBiel commented Jun 5, 2020

Could probably use some Color class in order to be able to accept multiple formats as well

the main format should be int, because one can simply 0xABCDEF in order to convert a hex string to int.

@PgBiel PgBiel added this to the PyPI Release 1.0.0 milestone Jun 5, 2020
@leotrs
Copy link
Contributor Author

leotrs commented Jun 6, 2020

So the problem right now is that the colors can be accessed in at least three different ways: constants.COLOR_MAP['BLACK'], simply as BLACK , and PALETTE. The latter one is only ever used once in the code and I think should be deprecated. Right now, we are manipulating locals in order to dump the contents of COLOR_MAP into the scope of constants. Not sure if we want to do that. I don't think the code uses COLOR_MAP at all, so why not just define all its contents as variables from the start? These could be either hex strings, or Color instances, as @PgBiel suggests

@leotrs
Copy link
Contributor Author

leotrs commented Jul 10, 2020

I still think we should move all colors to something like manim.colors, and turn them all into Colour instances too. We can easily do this in a backwards-compatible way.

@leotrs
Copy link
Contributor Author

leotrs commented Oct 8, 2020

#488 implements this.

@leotrs leotrs closed this as completed Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:deprecation Deprecation, or removal of deprecated code refactor Refactor or redesign of existing code
Projects
None yet
Development

No branches or pull requests

3 participants