-
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
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`.
|
||
|
||
class _OverrideAnimateDecorator(Protocol): | ||
def __call__(self, decorated: _Decorated, /) -> _Decorated: ... |
Check notice
Code scanning / CodeQL
Statement has no effect Note
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.
It's a callback protocol, I've used it to annotate the override_animate
function return value. I've used a callback protocol beacuse the _Decorated
TypeVar should be defined in the scope of that returned callable, not the override_animate
function itself.
@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`.
manim/renderer/shader_wrapper.py
Outdated
@@ -73,7 +82,7 @@ def copy(self): | |||
result.texture_paths = dict(self.texture_paths) | |||
return result | |||
|
|||
def is_valid(self): | |||
def is_valid(self, /) -> bool: |
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.
I can see that the slash separator '/' have been added in multiple locations in the code and I am a bit puzzled over what the benefit is of doing that. Could you explain your reasoning for this change?
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.
Oops, that was a mistake! Thanks for fixing it...
if TYPE_CHECKING: | ||
|
||
@overload | ||
def reverse(maybe_list: None) -> None: ... |
Check notice
Code scanning / CodeQL
Statement has no effect Note
@overload | ||
def reverse(maybe_list: None) -> None: ... | ||
@overload | ||
def reverse(maybe_list: Sequence[_T]) -> list[_T]: ... |
Check notice
Code scanning / CodeQL
Statement has no effect Note
@overload | ||
def reverse(maybe_list: Sequence[_T]) -> list[_T]: ... | ||
@overload | ||
def reverse(maybe_list: Sequence[_T] | None) -> list[_T] | None: ... |
Check notice
Code scanning / CodeQL
Statement has no effect Note
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.
Looks good to me!
Thanks for the effort put into this.
@henrikmidtiby Happy to help this awesome project! By the way, those |
Well that makes sense. |
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