-
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`.
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 So yes, I think you're right: I should've used This reminds me I still have to check if extra Edit: they're not supported, but they I've opened #3375 to track this problem (among other things). |
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 |
Ah, missed this part of your comment:
Yes, I agree it would be a solution; however, I think in some cases (like this very very long function) it pollutes the namespace and maybe harms code readibility. It also requires updating absolutely all references without missing anything, and has therefore to be reviewed with extreme care. In languages like Rust or Swift you can clearly shadow variables with a redeclaration ( Because type checkers like mypy are evidently trying to support this kind of pattern (see Also, I don't understand why mypy is still complaining about it, even if I have enabled the stable Anyways, if you still think we should use different names, I don't feel too strongly about this: I'll update the PR accordingly. |
Yes, I thought about that: I was trying to keep the changes as self-contained as possible. But it doesn't look like it should be too hard, I'll try and annotate those methods asap. Edit: done By the way, thank you @henrikmidtiby for the review! |
Ah, one last thing: if you reckon that the |
@RBerga06 I am happy to provide feedback. I really like the use use of
Regarding the issue I get your point that the type checker should be able to deal with the situation, this is however not the case yet ... For me the cost of polluting the namespace with one additional variable, is worth it, if we can get rid of any Regarding to locate a common subset of Finally the size of this PR is getting quite large with multiple changes at once (e.g. add type annotations and update dependency on typing-extensions). It is much easier for the reviewers to handle several small PR than one large PR. @chopan050 Would you have time to look at this PR? |
Yes, I agree this is a pretty large PR. Given that I'll update this PR accordingly ASAP (thus annotating |
…version that supports PEP 728." This reverts commit 69b96c6.
…e `**kwargs: Any`.
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