Skip to content

Adding type annotations to scene.py and vector_space_scene.py #4260

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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

henrikmidtiby
Copy link
Contributor

Overview: What does this pull request change?

Further Information and Comments

This pull request is related to the ongoing effort of adding type annotations to Manim
#3375

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Count: 307 errors

Type annotations on scene/vector_space_scene.py

Add type annotations to scene/vector_space_scene.py

Mypy count: 210

Reverting two changes that triggers an error in the automatic testing.

Further work on type hinting.

Avoid forwarding positional arguments from Arrow to Line in the constructor.

Revert "Avoid forwarding positional arguments from Arrow to Line in the constructor."

This reverts commit 80ae857.

Removed several type ignore statements and addressed comments from JasonGrace2282

Revert "Activate mypy check of mobject.geometry.*"

This reverts commit d477c9a.

Revert "Removed several type ignore statements and addressed comments from JasonGrace2282"

This reverts commit 07bbe3f.

Added type annotations to zoomed_scene.py

Error count: 308 -> 303

Adding type annotations to all methods in vector_space_scene.py

Error count: 303 -> 272

Get rid of no-untyped-call errors from my in the vector_space_scene.py file

Error count: 272 -> 343

Handle type issues related to ManimColor in vector_space_scene.py

Handle var-annotated issues in vector_space_scene.py

Error count: 332 -> 330

Handling has-type type errors in vector_space_scene.py

Error count: 330 -> 285

Handled name-defined type issues in vector_space_scene.py

Error count: 285 -> 282

Address type issue with calling an untyped method.

Error count: 282 -> 281

Fix some typing issues in transform_mathcing_parts.py

Change stroke_width to float in vector_space_scene.py

Handled a few type errors.

Error count: 267

Handled several typing issues in three_d_scene.py

Error count: 267 -> 248

Dealing with type errors in scene_file_writer.py

Error count: 248 -> 216

Ensured that all methods in scene.py have type declarations.

Error count: 216 -> 225

Handle type issues related to interactivity by asserting that the camera is the OpenGLCamera

Error count: 225 -> 182

Handle type issues in scene.py

Error count: 182 -> 167

Asserting that the renderer or camera is of the proper type to use certain methods.

This is mainly related to interactive elements and the 3D camera used in the ThreeDScene

Error count: 167 -> 143

Avoid cyclic import of dependencies

Error count: 143 -> 143

Handling no-untyped-call type errors in manim/scene/scene.py

Error count: 143 -> 131

Handling assignment type errors in manim/scene/*.py

Error count: 131 -> 121

Handling arg-type type errors in manim/scene/*.py

Error count: 121 -> 116

Handling arg-type type errors in manim/scene/*.py

Error count: 116 -> 112

Fixing various type errors

Error count: 112 -> 102

Fixing various type errors

Error count: 102 -> 97

Fixing various type errors

Error count: 97 -> 90

Some aggressive changes to silence a significant number of type errors.

Error count: 90 -> 66

Commented out an import (IPython) that makes the CI tests fail.

Fix various type errors.

More type annotations.

Code cleanup.

Remove the property mobject_updater_lists of the Scene class as it is not used anywhere.

Handle import-untyped typing issues.

More work on type annotations in manin/scene/.*

More work on scenes/*.py looking at the dependency opengl_renderer.py

More work on types in scenes/*.py

Ignored an old bunch of type ignore statements.

More work on dependencies for scene.py

More work on dependencies for scene.py
Comment on lines +14 to +18
from manim.mobject.opengl.opengl_mobject import (
OpenGLMobject,
OpenGLPoint,
_AnimationBuilder,
)

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
manim.mobject.opengl.opengl_mobject
begins an import cycle.
render_opengl_vectorized_mobject_stroke,
)

if TYPE_CHECKING:

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Scene occurs after the cyclic
import
of manim.renderer.opengl_renderer.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Scene occurs after the cyclic
import
of manim.renderer.opengl_renderer.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Scene occurs after the cyclic
import
of manim.renderer.opengl_renderer.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Scene occurs after the cyclic
import
of manim.renderer.opengl_renderer.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Scene occurs after the cyclic
import
of manim.renderer.opengl_renderer.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Scene occurs after the cyclic
import
of manim.renderer.opengl_renderer.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Scene occurs after the cyclic
import
of manim.renderer.opengl_renderer.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Scene occurs after the cyclic
import
of manim.renderer.opengl_renderer.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Scene occurs after the cyclic
import
of manim.renderer.opengl_renderer.
import numpy.typing as npt
from typing_extensions import Self

from manim.animation.animation import Animation

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'Animation' may not be defined if module
manim.animation.animation
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Animation occurs after the cyclic
import
of manim.renderer.opengl_renderer.
'Animation' may not be defined if module
manim.animation.animation
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Animation occurs after the cyclic
import
of manim.renderer.opengl_renderer.
'Animation' may not be defined if module
manim.animation.animation
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Animation occurs after the cyclic
import
of manim.renderer.opengl_renderer.

from .. import config, logger
from ..animation.animation import Animation, Wait, prepare_animation
from ..camera.camera import Camera
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, OpenGLMobject, OpenGLRenderer

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'OpenGLCamera' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.scene.scene
, as the
definition
of OpenGLCamera occurs after the cyclic
import
of manim.scene.scene.
'OpenGLCamera' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.scene.scene
, as the
definition
of OpenGLCamera occurs after the cyclic
import
of manim.scene.scene.
'OpenGLCamera' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.scene.scene
, as the
definition
of OpenGLCamera occurs after the cyclic
import
of manim.scene.scene.
'OpenGLCamera' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.scene.scene
, as the
definition
of OpenGLCamera occurs after the cyclic
import
of manim.scene.scene.
'OpenGLCamera' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.scene.scene
, as the
definition
of OpenGLCamera occurs after the cyclic
import
of manim.scene.scene.

from .. import config, logger
from ..animation.animation import Animation, Wait, prepare_animation
from ..camera.camera import Camera
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, OpenGLMobject, OpenGLRenderer

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.scene.scene
, as the
definition
of OpenGLRenderer occurs after the cyclic
import
of manim.scene.scene.
'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.scene.scene
, as the
definition
of OpenGLRenderer occurs after the cyclic
import
of manim.scene.scene.
'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.scene.scene
, as the
definition
of OpenGLRenderer occurs after the cyclic
import
of manim.scene.scene.
'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.scene.scene
, as the
definition
of OpenGLRenderer occurs after the cyclic
import
of manim.scene.scene.
'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.scene.scene
, as the
definition
of OpenGLRenderer occurs after the cyclic
import
of manim.scene.scene.
@henrikmidtiby henrikmidtiby force-pushed the Typing_scene_take_two branch from 4b40f10 to 04a437d Compare May 26, 2025 19:33
from .. import __version__, config
from ..utils.module_ops import scene_classes_from_file

if TYPE_CHECKING:
from ..renderer.opengl_renderer import OpenGLRenderer

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.gui.gui
, as the
definition
of OpenGLRenderer occurs after the cyclic
import
of manim.gui.gui.
'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.gui.gui
, as the
definition
of OpenGLRenderer occurs after the cyclic
import
of manim.gui.gui.
'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.gui.gui
, as the
definition
of OpenGLRenderer occurs after the cyclic
import
of manim.gui.gui.
'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.gui.gui
, as the
definition
of OpenGLRenderer occurs after the cyclic
import
of manim.gui.gui.
'OpenGLRenderer' may not be defined if module
manim.renderer.opengl_renderer
is imported before module
manim.gui.gui
, as the
definition
of OpenGLRenderer occurs after the cyclic
import
of manim.gui.gui.
@@ -35,6 +38,15 @@
render_opengl_vectorized_mobject_stroke,
)

if TYPE_CHECKING:

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'Mobject' may not be defined if module
manim.mobject.mobject
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Mobject occurs after the cyclic
import
of manim.renderer.opengl_renderer.
'Mobject' may not be defined if module
manim.mobject.mobject
is imported before module
manim.renderer.opengl_renderer
, as the
definition
of Mobject occurs after the cyclic
import
of manim.renderer.opengl_renderer.
@@ -411,8 +423,12 @@
self.skip_animations = True
raise EndSceneEarlyException()

from manim.utils.caching import handle_caching_play

Check failure

Code scanning / CodeQL

Module-level cyclic import

'handle_caching_play' may not be defined if module [manim.utils.caching](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of handle_caching_play occurs after the cyclic [import](4) of manim.renderer.opengl_renderer. 'handle_caching_play' may not be defined if module [manim.utils.caching](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of handle_caching_play occurs after the cyclic [import](5) of manim.renderer.opengl_renderer. 'handle_caching_play' may not be defined if module [manim.utils.caching](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of handle_caching_play occurs after the cyclic [import](6) of manim.renderer.opengl_renderer.
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, OpenGLMobject, OpenGLRenderer

Check failure

Code scanning / CodeQL

Module-level cyclic import

'OpenGLMobject' may not be defined if module [manim.renderer.opengl_renderer](1) is imported before module [manim.scene.scene](2), as the [definition](3) of OpenGLMobject occurs after the cyclic [import](4) of manim.scene.scene.
@@ -216,6 +226,8 @@


class OpenGLRenderer:
from ..scene.scene_file_writer import SceneFileWriter

Check failure

Code scanning / CodeQL

Module-level cyclic import

'SceneFileWriter' may not be defined if module [manim.scene.scene_file_writer](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of SceneFileWriter occurs after the cyclic [import](4) of manim.renderer.opengl_renderer. 'SceneFileWriter' may not be defined if module [manim.scene.scene_file_writer](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of SceneFileWriter occurs after the cyclic [import](5) of manim.renderer.opengl_renderer.


if TYPE_CHECKING:
from manim.scene.scene import Scene

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Scene' may not be defined if module [manim.scene.scene](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of Scene occurs after the cyclic [import](4) of manim.renderer.opengl_renderer. 'Scene' may not be defined if module [manim.scene.scene](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of Scene occurs after the cyclic [import](5) of manim.renderer.opengl_renderer. 'Scene' may not be defined if module [manim.scene.scene](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of Scene occurs after the cyclic [import](6) of manim.renderer.opengl_renderer. 'Scene' may not be defined if module [manim.scene.scene](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of Scene occurs after the cyclic [import](7) of manim.renderer.opengl_renderer. 'Scene' may not be defined if module [manim.scene.scene](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of Scene occurs after the cyclic [import](8) of manim.renderer.opengl_renderer. 'Scene' may not be defined if module [manim.scene.scene](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of Scene occurs after the cyclic [import](9) of manim.renderer.opengl_renderer. 'Scene' may not be defined if module [manim.scene.scene](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of Scene occurs after the cyclic [import](10) of manim.renderer.opengl_renderer. 'Scene' may not be defined if module [manim.scene.scene](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of Scene occurs after the cyclic [import](11) of manim.renderer.opengl_renderer. 'Scene' may not be defined if module [manim.scene.scene](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of Scene occurs after the cyclic [import](12) of manim.renderer.opengl_renderer.
from typing_extensions import Self

from manim.animation.animation import Animation
from manim.mobject.mobject import Mobject

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of Mobject occurs after the cyclic [import](4) of manim.renderer.opengl_renderer. 'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.renderer.opengl_renderer](2), as the [definition](3) of Mobject occurs after the cyclic [import](5) of manim.renderer.opengl_renderer.
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.Mobject]:

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
@@ -448,7 +456,7 @@
use_z_index=self.renderer.camera.use_z_index,
)

def add(self, *mobjects: Mobject):
def add(self, *mobjects: mobject.Mobject | OpenGLMobject) -> Self:

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](4) of manim.scene.scene. 'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](5) of manim.scene.scene.

def remove(self, *mobjects: Mobject):
def remove(self, *mobjects: mobject.Mobject) -> Self:

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.

def remove(self, *mobjects: Mobject):
def remove(self, *mobjects: mobject.Mobject) -> Self:

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](4) of manim.scene.scene. 'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](5) of manim.scene.scene.
@@ -703,7 +727,7 @@
return new_mobjects

# TODO, remove this, and calls to this
def add_foreground_mobjects(self, *mobjects: Mobject):
def add_foreground_mobjects(self, *mobjects: mobject.Mobject) -> Scene:

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](4) of manim.scene.scene. 'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](5) of manim.scene.scene.
@@ -739,7 +763,7 @@
"""
return self.add_foreground_mobjects(mobject)

def remove_foreground_mobjects(self, *to_remove: Mobject):
def remove_foreground_mobjects(self, *to_remove: mobject.Mobject) -> Scene:

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](4) of manim.scene.scene. 'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](5) of manim.scene.scene.
@@ -774,7 +798,7 @@
"""
return self.remove_foreground_mobjects(mobject)

def bring_to_front(self, *mobjects: Mobject):
def bring_to_front(self, *mobjects: mobject.Mobject) -> Scene:

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](4) of manim.scene.scene. 'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](5) of manim.scene.scene.
@@ -793,7 +817,7 @@
self.add(*mobjects)
return self

def bring_to_back(self, *mobjects: Mobject):
def bring_to_back(self, *mobjects: mobject.Mobject) -> Scene:

Check failure

Code scanning / CodeQL

Module-level cyclic import

'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](4) of manim.scene.scene. 'Mobject' may not be defined if module [manim.mobject.mobject](1) is imported before module [manim.scene.scene](2), as the [definition](3) of Mobject occurs after the cyclic [import](5) of manim.scene.scene.
@henrikmidtiby henrikmidtiby force-pushed the Typing_scene_take_two branch from 8c6fc74 to 2e45b3b Compare May 27, 2025 11:34
@henrikmidtiby henrikmidtiby mentioned this pull request May 27, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

1 participant