-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Implemented :meth:.Mobject.set_default
, a mechanism for changing default values of keyword arguments
#2075
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
Conversation
for more information, see https://pre-commit.ci
... I just discovered one possible error: When one tries to set a non-existing parameter, or misspells a parameter, setting the parameter is still possible. Only when the mobject is called later, the error occurs (see screenshot below). |
Thanks for checking this out and for your comments, @kolibril13!
What would be the benefit? I think
I don't see an effective way of dealing with this, unfortunately -- a class like
Unfortunately not possible, or at least I can't think of a good way to do it.
This would require additional bookkeeping, in the simplest version we could just store a copy of
I don't know how autocompletion for keyword parameters works, but I doubt it is possible in this case. All of this is unfortunate, but at least the error that will be raised if you misspelled a keyword is rather explicit and will point towards the source quickly.
This is, as you mention, a feature and not a bug. It simply is how inheritance works; if there are unexpected results that come with it, this is on us for not documenting inheritance properly. I don't know how we could change this, even if we wanted to. |
That would be amazing! Do you have time to add this feature?
Yep, I also think it is a feature. Looking at: https://docs.manim.community/en/stable/reference/manim.mobject.matrix.IntegerMatrix.html#manim.mobject.matrix.IntegerMatrix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice feature! Working well for me. Can we also add it to OpenGLMobject
please for opengl compatibility?
Interestingly it also works with required args, making them no longer required as you can set their defaults
class RegularPolygramExample(Scene):
def construct(self):
RegularPolygram.change_default(num_vertices=6)
pentagram = RegularPolygram()
self.add(pentagram)
I don't really agree with
Sure, I'll figure something out. Instead of introducing a second method, it might be easier to reset the defaults if the method is called without arguments.
Maybe as a follow-up if there is interest for it.
You are completely right! Matrix doesn't inherit from MathTex, I misspoke; Matrix "just" uses MathTex (or Tex, but as Tex inherits from MathTex that doesn't really matter) for writing its components. Similar for Integer, or DecimalNumber. But anyhow: there still is not much we can do about it, except document this better.
Yeah, sure. I'll just copy the code over. (In moments like these, I do wish that we had a common abstract base class for both Mobject and OpenGLMobject.)
Yep, this is because the implementation is as silly as it is. Whatever you pass to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
Good point, I am convinced that
I just wanted to mention the idea, I don't find it too important, though.
Completely agree on that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the restore option!
Great addition! Can we have a separate file full of defaults being changed like Also, I echo the sentiment of not liking change_default. I don't hate it, but I do kinda prefer .default or even set_default (I don't understand what you were talking about as to why you don't like this option). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a really great feature, and perfect for implementing themes! No strong opinions either way, but I still slightly prefer set_default
over change_default
.
You can do that, sure! However, this is something users have to do on their own -- we should not encourage anyone to edit the library code.
I don't like As for It seems pretty much everyone here is in favor of Thanks everyone for your feedback! |
.Mobject.set_default
, a mechanism for changing default values of keyword arguments
I don't mean a |
Yes, this is within scope of #2015 :) |
I'm quite late to the party, but this is a great addition! Especially in support of the theming idea. :)) |
We could have a theme gallery similar to this one: https://sphinx-themes.org/ |
I'd rather people use this feature to develop their own personal styles and use them throughout more than 1 video, but I am not opposed to a theme gallery. |
Can we merge this today? :) |
I am merging this pr now, so that it is part of the next release. |
Overview: What does this pull request change?
There has been a lot of discussion about default values for Mobjects (I'll go through the list of issues and link the related ones in a bit). This is a very, very, very, simple (read: it is not particularly clever or involved) proposal which allows users to change the default values of the keyword arguments of a given class.
This new feature allows to change the default value of keyword arguments passed to the constructor of mobjects.
For example, after running
Text.set_default(color=BLACK)
, new texts likeText("Hello world!")
will be colored black by default. See the documentation of :meth:
.Mobject.set_default
for moredetails.
Motivation and Explanation: Why and how do your changes improve the library?
Changing default values is something very common, and it should be easy to do. Speaking from a big-picture point of view, there are two possible approaches: storing default values in a separate module (
config.defaults
?), or storing them in the mobject itself.I like this proposed solution, because (a) it is rather simple (b) if we decide to add more infrastructure to default values (e.g., keeping track of values, allowing to save/restore configurations, whatever) the method-interface via
.change_default(**kwargs)
can be extended and appropriately modified easily without introducing breaking changes.Links to added or changed documentation pages
https://manimce--2075.org.readthedocs.build/en/2075/reference/manim.mobject.mobject.Mobject.html#manim.mobject.mobject.Mobject.change_default
Further Information and Comments
Reviewer Checklist