-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Type annotations for manim/scene/*.py #3981
base: main
Are you sure you want to change the base?
Type annotations for manim/scene/*.py #3981
Conversation
…he constructor." This reverts commit 80ae857.
This reverts commit d477c9a.
… from JasonGrace2282" This reverts commit 07bbe3f.
Error count: 308 -> 303
Error count: 303 -> 272
…y file Error count: 272 -> 343
Error count: 332 -> 330
Error count: 330 -> 285
Error count: 285 -> 282
Error count: 282 -> 281
Error count: 267
Error count: 267 -> 248
Error count: 248 -> 216
Error count: 216 -> 225
…era is the OpenGLCamera Error count: 225 -> 182
Error count: 182 -> 167
…rtain methods. This is mainly related to interactive elements and the 3D camera used in the ThreeDScene Error count: 167 -> 143
Error count: 143 -> 143
Error count: 143 -> 131
Error count: 131 -> 121
Error count: 121 -> 116
Error count: 116 -> 112
Error count: 112 -> 102
Error count: 102 -> 97
Error count: 97 -> 90
Error count: 90 -> 66
6c137ee
to
4c14674
Compare
@@ -11,6 +11,8 @@ | |||
|
|||
|
|||
from .. import __version__, config | |||
from ..renderer.cairo_renderer import CairoRenderer |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
manim.renderer.cairo_renderer
manim.gui.gui
definition
import
'CairoRenderer' may not be defined if module
manim.renderer.cairo_renderer
manim.gui.gui
definition
import
'CairoRenderer' may not be defined if module
manim.renderer.cairo_renderer
manim.gui.gui
definition
import
'CairoRenderer' may not be defined if module
manim.renderer.cairo_renderer
manim.gui.gui
definition
import
'CairoRenderer' may not be defined if module
manim.renderer.cairo_renderer
manim.gui.gui
definition
import
'CairoRenderer' may not be defined if module
manim.renderer.cairo_renderer
manim.gui.gui
definition
import
@@ -11,6 +11,8 @@ | |||
|
|||
|
|||
from .. import __version__, config | |||
from ..renderer.cairo_renderer import CairoRenderer | |||
from ..renderer.opengl_renderer import OpenGLRenderer |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
manim.renderer.opengl_renderer
manim.gui.gui
definition
import
'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
manim.gui.gui
definition
import
'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
manim.gui.gui
definition
import
'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
manim.gui.gui
definition
import
if TYPE_CHECKING: | ||
from typing_extensions import Self | ||
|
||
from manim.mobject.mobject import Mobject |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
manim.mobject.mobject
manim.renderer.opengl_renderer
definition
import
'Mobject' may not be defined if module
manim.mobject.mobject
manim.renderer.opengl_renderer
definition
import
from typing_extensions import Self | ||
|
||
from manim.mobject.mobject import Mobject | ||
from manim.scene.scene import Scene |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
manim.scene.scene
manim.renderer.opengl_renderer
definition
import
'Scene' may not be defined if module
manim.scene.scene
manim.renderer.opengl_renderer
definition
import
'Scene' may not be defined if module
manim.scene.scene
manim.renderer.opengl_renderer
definition
import
'Scene' may not be defined if module
manim.scene.scene
manim.renderer.opengl_renderer
definition
import
'Scene' may not be defined if module
manim.scene.scene
manim.renderer.opengl_renderer
definition
import
'Scene' may not be defined if module
manim.scene.scene
manim.renderer.opengl_renderer
definition
import
'Scene' may not be defined if module
manim.scene.scene
manim.renderer.opengl_renderer
definition
import
'Scene' may not be defined if module
manim.scene.scene
manim.renderer.opengl_renderer
definition
import
'Scene' may not be defined if module
manim.scene.scene
manim.renderer.opengl_renderer
definition
import
from ..constants import * | ||
from ..gui.gui import configure_pygui | ||
from ..renderer.cairo_renderer import CairoRenderer | ||
from ..renderer.opengl_renderer import OpenGLRenderer | ||
from ..renderer.opengl_renderer import OpenGLCamera, OpenGLRenderer |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
manim.renderer.opengl_renderer
manim.scene.scene
definition
import
'OpenGLCamera' may not be defined if module
manim.renderer.opengl_renderer
manim.scene.scene
definition
import
'OpenGLCamera' may not be defined if module
manim.renderer.opengl_renderer
manim.scene.scene
definition
import
'OpenGLCamera' may not be defined if module
manim.renderer.opengl_renderer
manim.scene.scene
definition
import
num_families = sum((mobject in family) for family in families) | ||
return num_families == 1 | ||
|
||
return list(filter(is_top_level, self.mobjects)) | ||
|
||
def get_mobject_family_members(self): | ||
def get_mobject_family_members(self) -> list[Mobject]: |
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns Note
@@ -493,7 +514,7 @@ | |||
self.add(mob) | |||
curr_mobjects += mob.get_family() | |||
|
|||
def remove(self, *mobjects: Mobject): | |||
def remove(self, *mobjects: Mobject) -> Self: |
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns Note
if not self.check_interactive_embed_is_valid(): | ||
return | ||
self.interactive_mode = True | ||
|
||
def ipython(shell, namespace): | ||
def ipython(shell: InteractiveShellEmbed, namespace: dict[str, Any]) -> None: |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
from .section import DefaultSectionType, Section | ||
|
||
if TYPE_CHECKING: | ||
from manim.renderer.cairo_renderer import CairoRenderer |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
manim.renderer.cairo_renderer
manim.scene.scene_file_writer
definition
import
'CairoRenderer' may not be defined if module
manim.renderer.cairo_renderer
manim.scene.scene_file_writer
definition
import
'CairoRenderer' may not be defined if module
manim.renderer.cairo_renderer
manim.scene.scene_file_writer
definition
import
'CairoRenderer' may not be defined if module
manim.renderer.cairo_renderer
manim.scene.scene_file_writer
definition
import
'CairoRenderer' may not be defined if module
manim.renderer.cairo_renderer
manim.scene.scene_file_writer
definition
import
'CairoRenderer' may not be defined if module
manim.renderer.cairo_renderer
manim.scene.scene_file_writer
definition
import
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from manim.mobject.mobject import Mobject |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
manim.mobject.mobject
manim.utils.family_ops
definition
import
'Mobject' may not be defined if module
manim.mobject.mobject
manim.utils.family_ops
definition
import
… not used anywhere.
@JasonGrace2282 I need some help to proceed with this work. At the current state of the code, there are 75 errors from mypy when the errors from mypy-manim.scene is no longer ignored.
|
Firstly, I recommend that you resolve conflicts with the master branch :) |
@JasonGrace2282 Thanks for the input. |
Overview: What does this pull request change?
The pull request add type annotations to the files manim/scene/*.py and some of its dependencies.
The request is still a work in progress, as mypy currently lists 90 errors.
With the pull request I hope to get some feedback and advise on how to proceed with the work.
The pull request is a continuation of the work in #3961
Motivation and Explanation: Why and how do your changes improve the library?
Type annotations help identify errors during development.
Further Information and Comments
I would suggest to make some changes to certain default values.
https://github.com/henrikmidtiby/manim/blob/6c137ee0f9f7b414bd5c1e0b6657eeaab005e088/manim/scene/scene.py#L128-L131
https://github.com/henrikmidtiby/manim/blob/6c137ee0f9f7b414bd5c1e0b6657eeaab005e088/manim/scene/scene.py#L119-L122
https://github.com/henrikmidtiby/manim/blob/6c137ee0f9f7b414bd5c1e0b6657eeaab005e088/manim/scene/scene.py#L119-L122
A change related to the background of a new Camera instance.
https://github.com/henrikmidtiby/manim/blob/6c137ee0f9f7b414bd5c1e0b6657eeaab005e088/manim/scene/vector_space_scene.py#L133-L135
It appears as the property
target_text
is not really used for something.https://github.com/henrikmidtiby/manim/blob/6c137ee0f9f7b414bd5c1e0b6657eeaab005e088/manim/scene/vector_space_scene.py#L1117-L1122
In some cases I have chosen to insert assertions about the type of certain data.
See e.g. here. Is this a suitable approach?
https://github.com/henrikmidtiby/manim/blob/6c137ee0f9f7b414bd5c1e0b6657eeaab005e088/manim/scene/scene.py#L1333
Reviewer Checklist