-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add generic set method and compatibility layer between properties and get_*/set_* methods #995
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
…_* and set_* methods
|
Oh, doctest is failing because EDIT: Nevermind I just need to make it expect |
|
@friedkeenan really cool feature! Look forward for it. Is it half way of cutting off get_stroke_width(), get_stroke_opacity() and and so on and replacing them with stroke_width, stroke_opacity ... properties? |
Yeah, the details of what will and won't be properties still needs to be hammered out on a case by case basis, but the plan is to migrate to a more property-driven API, and this PR is a step towards that |
…e layer are indeed methods
|
Okay, added documentation for the compatibility layer along with a warning saying it's not the preferred way of setting/getting attributes and that the layer could potentially go away in the future. |
|
I have trouble understanding this. |
Yes
Sounds good to me, will probably add that later then.
Well I was hoping for this to be merged so that the migration to properties can start, I was thinking incremental PRs could be made covering specific mobject attributes instead of one big go. Merging this would also allow users creating their own |
I also think that, but if you plan to do a PR starting the work right after this one then it's ok. I just don't want that this gets forgotten. And, for the |
Personally I'm kinda itching to start migrating, I don't see this as a big issue.
Currently the compatibility layer only adds |
|
I see, then. Thanks for the clarification! |
|
Added |
behackl
left a comment
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 your efforts, and also thanks for the thorough documentation! LGTM.
Motivation
A generic
setmethod is useful for animating setting properties, as discussed in #787. The compatibility layer added also automatically maintains backwards compatibility with theget_*andset_*API for any added properties, which should leave code for added properties cleaner.Overview / Explanation for Changes
The
setmethod allows mobject attributes to be defined as properties instead of withget_*andset_*methods while allowing setting the properties to be animated with the.animatesyntax, which is more pythonic and leads to less unintuitive code, like howobj.color = BLUEdoesn't truly set the mobject's color to blue.The automatic compatibility layer allows you to create a mobject like so:
and still be able to use
get_blahandset_blahwithout having to create a mobject like so:the last line of which seems particularly unpythonic/unconventional/less readable to me.
The compatibility layer is useful for at least as long as we're in the process of transitioning to using properties for mobject attributes, and then once that transition is complete we can decide whether we want to keep the compatibility layer and just deprecate the corresponding
get_*andset_*methods, or if we want to remove them outright with a breaking change. The layer also does not interfere withget_*andset_*methods that are defined normally.I've also added unit tests to ensure all this works.
Oneline Summary of Changes
Testing Status
All tests pass locally.
Further Comments
Currently unsure of where/how to document the compatibility layer, or if it needs to be documented at all.
Acknowledgements
Reviewer Checklist