-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Making ManimColor an Immutable datatype #3455
Comments
I was wondering if it would be possible to make the colors inside |
ValueError: mutable default <class 'manim.utils.color.core.ManimColor'> for field color is not allowed: use default_factory
for Python 3.11manim
colors as default values in a dataclass
Weird. Just installed python 3.11.6 and installed manim and numpy in a fresh venv. FFMPEG version's also the same. Ran your code and everything rendered fine. Try a |
Sorry for the confusion. Seems like my provided code was not complete. from manim import *
from dataclasses import dataclass
@dataclass
class Array:
values: list[int | None]
color: str = WHITE # <- This causes an issue because Python now requires the default values to be non-mutable
class CreateThumbnail(Scene):
def construct(self):
text = Text(
'Some\nTitle', font_size=77
).center().shift(3 * LEFT).shift(2 * UP)
self.add(text)
# ... |
How does this work as a solution? from manim import *
from dataclasses import dataclass
from typing import ClassVar
@dataclass
class Array:
values: list[int | None]
color: ClassVar[ManimColor] = WHITE # <- No longer raises a ValueError
class CreateThumbnail(Scene):
def construct(self):
text = Text(
'Some\nTitle', font_size=77
).center().shift(3 * LEFT).shift(2 * UP)
self.add(text)
# ...``` |
It doesn't. What if we need several different arrays? This should be an instance variable. |
If you want to store it as a Making |
I would be happy to store it as another type as well. |
I mean i kind of wrote it immutable so there shouldn't be methods that change the color in place if i didn't miss anything, so what would be the thing that signifies it's immutable? |
Maybe making |
manim
colors as default values in a dataclass
Let's see if I can manage to do this, I think the main problem will be getting the constructor to work. If you're on Discord it would be nice if you could join the dev-chat to maybe work out a solution that also works for different use-cases. Because i never really had the time to look at semantics of Dataclasses in that context. |
Just joined the Discord community. |
Hi @MrDiver are there any updates on this? What you wanna do is get rid of the constructor and place all the logic inside a I think This might be helpful: https://chat.openai.com/share/511eb72a-c43f-442e-aa2a-8d48c9821c2e This is the stack overflow question: https://stackoverflow.com/questions/53756788/how-to-set-the-value-of-dataclass-field-in-post-init-when-frozen-true |
Hey, yes i was still experimenting with that and trying to find edge cases where we might run into problems see the HSL color class. So it seems like this should be fine as a long term change. |
Another thought would be adding a |
Description of bug / unexpected behavior
I'm trying to run manim with Python 3.11 (3.11.6 more specifically). Yet, I get a
ValueError
telling me thatManimColor
class has a mutable default for a field color.Expected behavior
It should work without errors.
How to reproduce the issue
Code for reproducing the problem
Place the following code in a file
main.py
Run the following command to compile:
Logs
Terminal output
System specifications
System Details
python/py/python3 --version
): 3.11pip list
): manim and numpyFFMPEG
Output of
ffmpeg -version
:The text was updated successfully, but these errors were encountered: