Suggestion: Replacing string constants with Enums #2821
MrDiver
started this conversation in
Suggestions and Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Enhancement proposal
There are a few places in manim which work on the basis of strings as a primary structure for comparing and matching in the code. This makes using the code more difficult for the user but also harder to understand for a typechecker. The example i stumbled upon is
arrange_in_grid
.manim/manim/mobject/mobject.py
Lines 2142 to 2154 in f88d64a
manim/manim/mobject/opengl/opengl_mobject.py
Lines 884 to 896 in f88d64a
Here we pass in strings for the comparison which sounds intially like a good idea. But without reading the documentation you can't know what argument to pass just by looking at the Types or using the autocomplete. Yes i know this is very specific. But with an enum like
Alignment
you could see that it's of type Alignment and then do something likeAlignment.LEFT
. I do not really know how i would do this in case of this function because there are 3 different Enums needed for this setup. But i also haven't spend much time thinking about it.So if someone more familiar with the mechanics of Enums in python has a good idea on how to approach something like this without cluttering the namespace with 100 different enums it would be nice.
There are also the global constants LEFT,RIGHT and so on which might easily be confused with the Enum. Maybe they could be integrated somehow ? But that sounds like it would end in more spaghetti code.
Beta Was this translation helpful? Give feedback.
All reactions