-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add type annotations to opengl_mobject.py
#4398
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
base: main
Are you sure you want to change the base?
Conversation
I also made the |
…`, because the `typing` one does not have the `default` argument.
…in `OpenGLMobject`.
I have also discovered and fixed a typo in |
…n `if TYPE_CHECKING` statement.
… `**kwargs` in a set of related methods.
It is not completely clear where extra For example, I noticed that the That's why, at first, I annotated I suspect the intention was to override the I think it would help to define a @henrikmidtiby whay do you think about this proposal? I'm asking you because I saw you're working on typing |
I also think clarifying the current state and intended |
…l_compatibility.py`" This reverts commit 1cd1550.
manim/mobject/opengl/*.py
manim/mobject/opengl/opengl_mobject.py
…ginal__init__` at class scope). I followed the advice of an existing `# TODO` comment and the implementation in `Mobject`. This also resolves a mypy error in this class (missing attribute). It's interesting because the `get_array_attrs` method is (was) only defined in three classes: - `Mobject` - `PMobject` - `OpenGLPMobject`
… the `override_animate()`.
…`_AnimationBuilder` and some methods in `OpenGLPoint`.
…al(…)` had to return `self`!
…to `ShaderWrapper` methods (not yet annotated).
…[no-any-return]`s for cases where mypy cannot understand operations on numpy arrays.
…t.fixed_orientation_center`
manim/mobject/opengl/opengl_mobject.py
opengl_mobject.py
Wow a lot of good stuff is happening here! Here comes a list of observations, that I have made about things that I would have done differently; which is not necessarily better...
|
Regarding the first two points, the If at some point I've used class A:
def foo(self, **kwargs: object) -> None: ...
class B(A):
def foo(self, x: int = 3, **kwargs: object) -> None: ...
def use_a(a: A):
a.foo(x="hello") # ok because "hello": str <: object
use_a(A()) # all fine
use_a(B()) # TypeError at runtime! In fact, type checkers should (and maybe do?) reject |
By the way, I have started using |
Yes, that actually makes sense. In a couple of places, I think I have tried my best to explain why the I'll try and explain the rest of them; although, if I recall correctly, they're all about incompatible assignment between Ah yes, there was also a very long function where we were shadowing function arguments with new variables in the function body and As a side note, I still cannot figure out how to get mypy correctly configured (I've always been a |
Overview: What does this pull request change?
Part of #3375.
Motivation and Explanation: Why and how do your changes improve the library?
This PR adds type annotations to
manim/mobject/opengl/opengl_mobject.py
, to improve type coverage formanim
's public interface.Edit: By thoroughly annotating a number of methods, I also discovered and fixed what appeared to be typos or mistakes. For reference, I'm listing them here, because these changes can in principle affect runtime behaviour.
OpenGLMobject.restore
(commit 40dc43f)**kwargs
being passed toOpenGLMobject.apply_points_function
that could lead to runtimeTypeError
s (see my comment below)OpenGLMobject.get_array_attrs()
method (commit 2909380)return self
inOpenGLMobject.pointwise_become_partial
(commit 5d5de9a)Reviewer Checklist