Skip to content
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

Typing vector space scene #4130

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: check-toml
name: Validate Poetry
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
rev: v0.9.2
hooks:
- id: ruff
name: ruff lint
Expand Down
24 changes: 15 additions & 9 deletions manim/_config/cli_colors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import configparser
from typing import Any
from typing import Any, cast

from cloup import Context, HelpFormatter, HelpTheme, Style

Expand All @@ -15,6 +15,9 @@ def parse_cli_ctx(parser: configparser.SectionProxy) -> dict[str, Any]:
"col1_max_width": int(parser["col1_max_width"]),
"col2_min_width": int(parser["col2_min_width"]),
"col_spacing": int(parser["col_spacing"]),
# TODO
# What should the default value of "row_sep" be?
# I cannot be None according to the typing in line 12.
"row_sep": parser["row_sep"] if parser["row_sep"] else None,
}
theme_settings = {}
Expand All @@ -37,22 +40,25 @@ def parse_cli_ctx(parser: configparser.SectionProxy) -> dict[str, Any]:
if theme is None:
formatter = HelpFormatter.settings(
theme=HelpTheme(**theme_settings),
**formatter_settings, # type: ignore[arg-type]
**formatter_settings,
)
elif theme.lower() == "dark":
formatter = HelpFormatter.settings(
theme=HelpTheme.dark().with_(**theme_settings),
**formatter_settings, # type: ignore[arg-type]
**formatter_settings,
)
elif theme.lower() == "light":
formatter = HelpFormatter.settings(
theme=HelpTheme.light().with_(**theme_settings),
**formatter_settings, # type: ignore[arg-type]
**formatter_settings,
)

return Context.settings(
align_option_groups=parser["align_option_groups"].lower() == "true",
align_sections=parser["align_sections"].lower() == "true",
show_constraints=True,
formatter_settings=formatter,
return cast(
dict[str, Any],
Context.settings(
align_option_groups=parser["align_option_groups"].lower() == "true",
align_sections=parser["align_sections"].lower() == "true",
show_constraints=True,
formatter_settings=formatter,
),
)
3 changes: 2 additions & 1 deletion manim/_config/logger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

if TYPE_CHECKING:
from pathlib import Path
from typing import Any

__all__ = ["make_logger", "parse_theme", "set_file_logger", "JSONFormatter"]

Expand Down Expand Up @@ -126,7 +127,7 @@ def parse_theme(parser: configparser.SectionProxy) -> Theme:
:func:`make_logger`.

"""
theme = {key.replace("_", "."): parser[key] for key in parser}
theme: dict[str, Any] = {key.replace("_", "."): parser[key] for key in parser}

theme["log.width"] = None if theme["log.width"] == "-1" else int(theme["log.width"])
theme["log.height"] = (
Expand Down
10 changes: 5 additions & 5 deletions manim/_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import sys
from collections.abc import Iterable, Iterator, Mapping, MutableMapping
from pathlib import Path
from typing import TYPE_CHECKING, Any, ClassVar, NoReturn
from typing import TYPE_CHECKING, Any, ClassVar, NoReturn, cast

import numpy as np

Expand Down Expand Up @@ -332,7 +332,7 @@ def __iter__(self) -> Iterator[str]:
def __len__(self) -> int:
return len(self._d)

def __contains__(self, key: object) -> bool:
def __contains__(self, key: str) -> bool:
try:
self.__getitem__(key)
return True
Expand Down Expand Up @@ -652,8 +652,8 @@ def digest_parser(self, parser: configparser.ConfigParser) -> Self:
self.window_size = window_size

# plugins
plugins = parser["CLI"].get("plugins", fallback="", raw=True)
plugins = [] if plugins == "" else plugins.split(",")
plugins_raw: str = parser["CLI"].get("plugins", fallback="", raw=True)
plugins: list[str] = [] if plugins_raw == "" else plugins_raw.split(",")
self.plugins = plugins
# the next two must be set AFTER digesting pixel_width and pixel_height
self["frame_height"] = parser["CLI"].getfloat("frame_height", 8.0)
Expand Down Expand Up @@ -1630,7 +1630,7 @@ def get_dir(self, key: str, **kwargs: Any) -> Path:
all_args.update(kwargs)
all_args["quality"] = f"{self.pixel_height}p{self.frame_rate:g}"

path = self._d[key]
path = cast(str, self._d[key])
while "{" in path:
try:
path = path.format(**all_args)
Expand Down
2 changes: 1 addition & 1 deletion manim/animation/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def __init__(
function: types.MethodType,
mobject: Mobject,
run_time: float = DEFAULT_POINTWISE_FUNCTION_RUN_TIME,
**kwargs,
**kwargs: Any,
) -> None:
super().__init__(mobject.apply_function, function, run_time=run_time, **kwargs)

Expand Down
6 changes: 3 additions & 3 deletions manim/mobject/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from manim.mobject.mobject import Mobject
from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
from manim.mobject.text.numbers import DecimalNumber, Integer
from manim.mobject.text.tex_mobject import MathTex, Tex

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'MathTex' may not be defined if module
manim.mobject.text.tex_mobject
is imported before module
manim.mobject.matrix
, as the
definition
of MathTex occurs after the cyclic
import
of manim.mobject.matrix.
'MathTex' may not be defined if module
manim.mobject.text.tex_mobject
is imported before module
manim.mobject.matrix
, as the
definition
of MathTex occurs after the cyclic
import
of manim.mobject.matrix.
'MathTex' may not be defined if module
manim.mobject.text.tex_mobject
is imported before module
manim.mobject.matrix
, as the
definition
of MathTex occurs after the cyclic
import
of manim.mobject.matrix.

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'Tex' may not be defined if module
manim.mobject.text.tex_mobject
is imported before module
manim.mobject.matrix
, as the
definition
of Tex occurs after the cyclic
import
of manim.mobject.matrix.
'Tex' may not be defined if module
manim.mobject.text.tex_mobject
is imported before module
manim.mobject.matrix
, as the
definition
of Tex occurs after the cyclic
import
of manim.mobject.matrix.
'Tex' may not be defined if module
manim.mobject.text.tex_mobject
is imported before module
manim.mobject.matrix
, as the
definition
of Tex occurs after the cyclic
import
of manim.mobject.matrix.

from ..constants import *
from ..mobject.types.vectorized_mobject import VGroup, VMobject
Expand Down Expand Up @@ -400,7 +400,7 @@
mob.add_background_rectangle()
return self

def get_mob_matrix(self):
def get_mob_matrix(self) -> list[VGroup]:
"""Return the underlying mob matrix mobjects.

Returns
Expand All @@ -410,7 +410,7 @@
"""
return self.mob_matrix

def get_entries(self):
def get_entries(self) -> VGroup:
"""Return the individual entries of the matrix.

Returns
Expand All @@ -435,7 +435,7 @@
"""
return self.elements

def get_brackets(self):
def get_brackets(self) -> VGroup:
r"""Return the bracket mobjects.

Returns
Expand Down
5 changes: 4 additions & 1 deletion manim/mobject/text/tex_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from manim import config, logger
from manim.constants import *
from manim.mobject.geometry.line import Line
from manim.mobject.geometry.line import Line, Vector

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'Line' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Line occurs after the cyclic
import
of manim.mobject.text.tex_mobject.
'Line' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Line occurs after the cyclic
import
of manim.mobject.text.tex_mobject.
'Line' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Line occurs after the cyclic
import
of manim.mobject.text.tex_mobject.
'Line' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Line occurs after the cyclic
import
of manim.mobject.text.tex_mobject.
'Line' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Line occurs after the cyclic
import
of manim.mobject.text.tex_mobject.
'Line' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Line occurs after the cyclic
import
of manim.mobject.text.tex_mobject.

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'Vector' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Vector occurs after the cyclic
import
of manim.mobject.text.tex_mobject.
'Vector' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Vector occurs after the cyclic
import
of manim.mobject.text.tex_mobject.
'Vector' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Vector occurs after the cyclic
import
of manim.mobject.text.tex_mobject.
'Vector' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Vector occurs after the cyclic
import
of manim.mobject.text.tex_mobject.
'Vector' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Vector occurs after the cyclic
import
of manim.mobject.text.tex_mobject.
'Vector' may not be defined if module
manim.mobject.geometry.line
is imported before module
manim.mobject.text.tex_mobject
, as the
definition
of Vector occurs after the cyclic
import
of manim.mobject.text.tex_mobject.
from manim.mobject.svg.svg_mobject import SVGMobject
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
from manim.utils.tex import TexTemplate
Expand Down Expand Up @@ -271,6 +271,9 @@
if self.tex_to_color_map is None:
self.tex_to_color_map = {}
self.tex_environment = tex_environment
self.target_text: MathTex | str = ""
self.kwargs = {}
self.vector: Vector = Vector()
self.brace_notation_split_occurred = False
self.tex_strings = self._break_up_tex_strings(tex_strings)
try:
Expand Down
4 changes: 3 additions & 1 deletion manim/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
from collections.abc import Sequence
from typing import Callable

from typing_extensions import Self

from manim.mobject.mobject import _AnimationBuilder


Expand Down Expand Up @@ -813,7 +815,7 @@ def bring_to_back(self, *mobjects: Mobject):
self.mobjects = list(mobjects) + self.mobjects
return self

def clear(self):
def clear(self) -> Self:
"""
Removes all mobjects present in self.mobjects
and self.foreground_mobjects from the scene.
Expand Down
Loading
Loading