Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Type hinting ipython_magic.py (#2171)

David Yangacd4d10600b3
diff --git a/manim/utils/ipython_magic.py b/manim/utils/ipython_magic.py
index 7405d62e6..cf50aa9b9 100644
--- a/manim/utils/ipython_magic.py
+++ b/manim/utils/ipython_magic.py
@@ -5,6 +5,7 @@ import os
import shutil
from datetime import datetime
from pathlib import Path
+from typing import Any, Dict, List
from manim import Group, config, logger, tempconfig
from manim.__main__ import main
@@ -12,6 +13,7 @@ from manim.renderer.shader import shader_program_cache
try:
from IPython import get_ipython
+ from IPython.core.interactiveshell import InteractiveShell
from IPython.core.magic import (
Magics,
line_cell_magic,
@@ -25,13 +27,18 @@ else:
@magics_class
class ManimMagic(Magics):
- def __init__(self, shell):
+ def __init__(self, shell: InteractiveShell) -> None:
super().__init__(shell)
self.rendered_files = {}
@needs_local_scope
@line_cell_magic
- def manim(self, line, cell=None, local_ns=None):
+ def manim(
+ self,
+ line: str,
+ cell: str = None,
+ local_ns: Dict[str, Any] = None,
+ ) -> None:
r"""Render Manim scenes contained in IPython cells.
Works as a line or cell magic.
@@ -169,7 +176,7 @@ else:
),
)
- def add_additional_args(self, args):
+ def add_additional_args(self, args: List[str]) -> List[str]:
additional_args = ["--jupyter"]
# Use webm to support transparency
if "-t" in args and "--format" not in args:
@@ -177,5 +184,5 @@ else:
return additional_args + args[:-1] + [""] + [args[-1]]
-def _generate_file_name():
+def _generate_file_name() -> str:
return config["scene_names"][0] + "@" + datetime.now().strftime("%Y-%m-%d@%H-%M-%S")