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

Fix Typing #3086

Merged
merged 101 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
bd4d123
first draft of color class + starting library conversion
MrDiver Nov 13, 2022
01e28fd
Merge branch 'main' into color_fix
MrDiver Nov 13, 2022
a0e85af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 13, 2022
8af3f81
Merge branch 'main' into color_fix
MrDiver Nov 19, 2022
332d327
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2022
da0806a
changed everything to Manim color todo: figure out circular dependenc…
MrDiver Nov 19, 2022
73ffb51
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2022
157c504
first working draft of new color version
MrDiver Dec 10, 2022
a7e4a3e
Merge branch 'main' into color_fix
MrDiver Dec 10, 2022
d21583d
resolving conflicts
MrDiver Dec 11, 2022
074345e
resolving conflicts
MrDiver Dec 11, 2022
128b8ab
resolving conflicts
MrDiver Dec 11, 2022
31bcdac
resolving conflicts
MrDiver Dec 11, 2022
27c0ddb
resolving conflicts
MrDiver Dec 11, 2022
195512a
changed default internal value of ManimColor to np.ndarray[float]
MrDiver Dec 16, 2022
9823616
starting to fix tests
MrDiver Dec 16, 2022
e638643
fixed more tests and changed precision of manim color
MrDiver Dec 17, 2022
7867aa3
removed premature color conversion
MrDiver Dec 17, 2022
a12507a
fixed some more tests
MrDiver Dec 17, 2022
15c4998
final test changes
MrDiver Dec 17, 2022
76d7cda
fix doctests
MrDiver Dec 17, 2022
a27aff4
fix for 3.8
MrDiver Dec 17, 2022
1580c82
fixing ManimColor string representation
MrDiver Dec 17, 2022
b2cc282
removing some unneccesary conversions
MrDiver Dec 17, 2022
2baeff5
moved community constants to manim_colors.py and added more color sta…
MrDiver Dec 22, 2022
86c5d07
Merge branch 'main' into color_fix
MrDiver Dec 22, 2022
b44a3e9
Merge branch 'color_fix' of github.com:MrDiver/manim into 52-fix-typing
MrDiver Dec 24, 2022
cd7a385
Added typing.py and typed bezier.py, core.py, constants.py fully
MrDiver Dec 25, 2022
47e16b6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 25, 2022
3193597
fixed codeql complaints
MrDiver Dec 25, 2022
bd3bf0c
add type ignore for np.allclose
MrDiver Dec 25, 2022
8c1b871
fixed import in three_dimensions
MrDiver Dec 25, 2022
2433c1d
added ignore for F401 back again in flake
MrDiver Dec 25, 2022
d32b267
added typings to coordinate_systems.py
alembcke Jan 7, 2023
0356591
Few improvements to `graphing/coordinate_systems.py`
Viicos Jan 20, 2023
b08e4a6
added some typings to mobject/geometry/line.py
alembcke Jan 20, 2023
ee865ff
updated typings for mobject/geometry/line.py
alembcke Jan 21, 2023
9eb6ed3
Add missing imports to `line.py`
Viicos Jan 21, 2023
561ef52
added typings to three_dimensions.py
alembcke Feb 6, 2023
bf2bcbf
Use `FunctionOverride` for animation overrides
Viicos Feb 18, 2023
1f56200
Remove `TYPE_CHECKING` check
Viicos Feb 18, 2023
802ab71
Revert "Remove `TYPE_CHECKING` check"
Viicos Feb 18, 2023
b11ffe2
Use `Self` in `coordinate_systems.py`
Viicos Feb 18, 2023
a41900c
Typehinted mobject.py and updated manim.typing.py
JasonGrace2282 Aug 6, 2023
c0f121c
Typed VMobject
JasonGrace2282 Aug 10, 2023
88f9b2d
Type-hinted manim.mobject.geometry
JasonGrace2282 Aug 10, 2023
17ce647
math.cos->np.cos, etc & fixed incorrect typehints
JasonGrace2282 Aug 10, 2023
747167b
Merge branch 'main' of github.com:ManimCommunity/manim into 52-fix-ty…
MrDiver Aug 11, 2023
2a71462
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2023
8a149ca
fix missing annotations import
MrDiver Aug 11, 2023
28d9b24
Merge branch '52-fix-typing' of github.com:MrDiver/manim into 52-fix-…
MrDiver Aug 11, 2023
6987498
TypeAlias fix in typing.py
MrDiver Aug 11, 2023
9026015
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2023
51922d1
Add ignore errors again to mypy because commits are not possible like…
MrDiver Aug 11, 2023
e8ab923
Merge main
Viicos Sep 22, 2023
106774d
Fix last typing issues
Viicos Sep 22, 2023
ca3154c
Update docs
Viicos Sep 22, 2023
920d15c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2023
c6183e8
Only type check manim
Viicos Sep 22, 2023
ad7043f
Try fixing pre-commit
Viicos Sep 22, 2023
1da1b99
fix merge
Viicos Sep 22, 2023
8522b59
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2023
6f95fd3
Fix compat
Viicos Sep 22, 2023
c2d7d42
Fix compat again
Viicos Sep 22, 2023
3a3d501
Fix imports compat
Viicos Sep 22, 2023
2189d01
Use union syntax
Viicos Sep 22, 2023
e62ade2
Use union syntax
Viicos Sep 22, 2023
4497734
Fix reduce_across_dimension
Viicos Sep 22, 2023
aadb22c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2023
0852403
Various test and merge fixes
Viicos Sep 22, 2023
b9fbf54
Doc fixes
Viicos Sep 22, 2023
0f108c0
Last doc fix
Viicos Sep 22, 2023
5160a1f
Revert usage of np over math
Viicos Sep 23, 2023
388b6d1
Bump numpy version
Viicos Sep 23, 2023
287c3ad
Remove obsolete duplicate example
Viicos Sep 23, 2023
0c0f875
Fixed Incorrect Typehint in manim.constants
JasonGrace2282 Sep 23, 2023
b87b594
Fix docstring typo
Viicos Sep 24, 2023
1c139af
More fixes
Viicos Sep 25, 2023
ffaa031
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 25, 2023
56501d7
docs fixes
Viicos Sep 25, 2023
921f450
Add internal aliases
Viicos Sep 25, 2023
4e3fe30
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 25, 2023
5663791
fix compat
Viicos Sep 25, 2023
f92ebd6
Merge remote-tracking branch 'origin/main' into 52-fix-typing
behackl Oct 27, 2023
feca683
line lengths in .rst file, formatting, typos
behackl Oct 28, 2023
2bcd8ac
add docstring for space_ops:cross2d
behackl Oct 28, 2023
5514ac4
add some more arrow tip typings (in a non-circular import causing way)
behackl Oct 28, 2023
b259a04
yes, this can be deleted
behackl Oct 28, 2023
e390082
fix formatting of example
behackl Oct 28, 2023
737189c
added docstring to bezier::inverse_interpolation
behackl Oct 28, 2023
3c4051f
added docstring + test for bezier::match_interpolate
behackl Oct 28, 2023
c7659d3
some improvements in coordinate_systems
behackl Oct 28, 2023
351353a
Vector -> Vector3
behackl Oct 28, 2023
3616c50
replaced np.ndarray with more appropriate type hints
behackl Oct 28, 2023
672b0e3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 28, 2023
84c9cdc
Apply feedback
Viicos Oct 29, 2023
4fed4af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2023
ad228f1
revert to previous (new) version
behackl Nov 2, 2023
c2b48f8
fix doctest
behackl Nov 3, 2023
948214e
fix ReST errors
behackl Nov 3, 2023
33d9e4a
Merge remote-tracking branch 'origin/main' into 52-fix-typing
behackl Nov 3, 2023
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
7 changes: 4 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[flake8]
# Exclude the grpc generated code
exclude = ./manim/grpc/gen/*
exclude = ./manim/grpc/gen/*, __pycache__,.git,
per-file-ignores = __init__.py:F401
max-complexity = 15
max-line-length = 88
statistics = True
Expand All @@ -9,7 +10,7 @@ rst-roles = attr,class,func,meth,mod,obj,ref,doc,exc
rst-directives = manim, SEEALSO, seealso
docstring-convention=numpy

select = A,A00,B,B9,C4,C90,D,E,F,F,PT,RST,SIM,W
select = A,A00,B,B9,C4,C90,D,E,F,F,PT,RST,SIM,W,F401

# General Compatibility
extend-ignore = E203, W503, D202, D212, D213, D404
Expand Down Expand Up @@ -40,4 +41,4 @@ extend-ignore = E203, W503, D202, D212, D213, D404

# Plug-in: flake8-rst-docstrings
RST201, RST203, RST210, RST212, RST213, RST215,
RST301, RST303,
RST301, RST303, RST499
86 changes: 57 additions & 29 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,30 +1,62 @@
[mypy]
show_error_codes = True

# ignore most files; should be checked once proper types have been implemented
[mypy-manim.__main__]
ignore_errors = True

[mypy-manim.camera.*]
ignore_errors = True

[mypy-manim.scene.*]
ignore_errors = True

[mypy-manim.cli.cfg.*]
ignore_errors = True

[mypy-manim.mobject.*]
ignore_errors = True

[mypy-manim._config.*]
ignore_errors = True

[mypy-manim.utils.*]
ignore_errors = True

[mypy-manim.animation.*]
strict = False
python_version = 3.10
; plugins = numpy.typing.mypy_plugin
ignore_errors = True
cache_fine_grained = True
use_fine_grained_cache = True

# Disallow Dynamic Typing
# disallow_any_unimported = True
# disallow_any_expr = False
# disallow_any_decorated = True
# disallow_any_explicit = True
# disallow_any_generics = True
# disallow_subclassing_any = True
#
# # Disallow Untyped Defs and Calls
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
# check_untyped_defs = False
# disallow_untyped_decorators = True
#
# # None and Optional Handling
# implicit_optional = False
# strict_optional = True
#
# # Configuring Warnings
# warn_redundant_casts = True
# warn_unused_ignores = True
warn_return_any = True
# warn_unreachable = True
#
# # Strictness Flags
# allow_untyped_globals = False
# allow_redefinition = False
# local_partial_types = False
# strict_equality = True
#
# # Configuring Error Messages
# show_error_context = True
# show_column_numbers = True
# show_error_codes = True
# pretty = True
# color_output = True
# error_summary = True
#
# disable_recursive_aliases = True

[mypy-manim.typing]
ignore_errors = False
[mypy-manim.constants]
ignore_errors = False
[mypy-manim.utils.color]
ignore_errors = False
[mypy-manim.utils]
ignore_errors = False
[mypy-manim.utils.bezier]
ignore_errors = False

# ---------------- We can't properly type this ------------------------

Expand All @@ -37,10 +69,6 @@ ignore_errors = True
[mypy-manimpango]
ignore_missing_imports = True

# Has stubs in 3.8
[mypy-numpy]
ignore_missing_imports = True

# Has stubs in 3.8
[mypy-pydub]
ignore_missing_imports = True
Expand Down
4 changes: 2 additions & 2 deletions manim/_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from pathlib import Path
from typing import Any, Iterable, Iterator

import colour
import numpy as np

from .. import constants
Expand Down Expand Up @@ -1094,9 +1093,10 @@ def format(self, val: str) -> None:
doc="Frame rate in frames per second.",
)

# TODO: This was parsed before maybe add ManimColor(val), but results in circular import
MrDiver marked this conversation as resolved.
Show resolved Hide resolved
background_color = property(
lambda self: self._d["background_color"],
lambda self, val: self._d.__setitem__("background_color", colour.Color(val)),
lambda self, val: self._d.__setitem__("background_color", val),
doc="Background color of the scene (-c).",
)

Expand Down
14 changes: 9 additions & 5 deletions manim/animation/changing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

from typing import Callable

from colour import Color

from manim._config import config
from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
from manim.utils.color import BLUE_B, BLUE_D, BLUE_E, GREY_BROWN, WHITE
from manim.utils.color import (
BLUE_B,
BLUE_D,
BLUE_E,
GREY_BROWN,
WHITE,
ParsableManimColor,
)
from manim.utils.rate_functions import smooth


Expand Down Expand Up @@ -140,7 +144,7 @@ def __init__(
self,
traced_point_func: Callable,
stroke_width: float = 2,
stroke_color: Color = WHITE,
stroke_color: ParsableManimColor | None = WHITE,
dissipating_time: float | None = None,
**kwargs,
):
Expand Down
7 changes: 3 additions & 4 deletions manim/animation/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def construct(self):
from typing import TYPE_CHECKING, Callable, Iterable, Sequence

import numpy as np
from colour import Color

if TYPE_CHECKING:
from manim.mobject.text.text_mobject import Text

from manim.mobject.opengl.opengl_surface import OpenGLSurface
from manim.mobject.opengl.opengl_vectorized_mobject import OpenGLVMobject
from manim.utils.color import ManimColor

from .. import config
from ..animation.animation import Animation
Expand All @@ -92,7 +92,7 @@ def construct(self):
from ..mobject.mobject import Group, Mobject
from ..mobject.types.vectorized_mobject import VMobject
from ..utils.bezier import integer_interpolate
from ..utils.rate_functions import double_smooth, linear, smooth
from ..utils.rate_functions import double_smooth, linear


class ShowPartial(Animation):
Expand Down Expand Up @@ -259,7 +259,7 @@ def get_outline(self) -> Mobject:
sm.set_stroke(color=self.get_stroke_color(sm), width=self.stroke_width)
return outline

def get_stroke_color(self, vmobject: VMobject | OpenGLVMobject) -> Color:
def get_stroke_color(self, vmobject: VMobject | OpenGLVMobject) -> ManimColor:
if self.stroke_color:
return self.stroke_color
elif vmobject.get_stroke_width() > 0:
Expand Down Expand Up @@ -404,7 +404,6 @@ def __init__(
reverse: bool = True,
**kwargs,
) -> None:

run_time: float | None = kwargs.pop("run_time", None)
lag_ratio: float | None = kwargs.pop("lag_ratio", None)
run_time, lag_ratio = self._set_default_config_from_length(
Expand Down
8 changes: 4 additions & 4 deletions manim/animation/indication.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def construct(self):
from typing import Callable, Iterable, Optional, Tuple, Type, Union

import numpy as np
from colour import Color

from manim.mobject.geometry.arc import Circle, Dot
from manim.mobject.geometry.line import Line
from manim.mobject.geometry.polygram import Rectangle
from manim.mobject.geometry.shape_matchers import SurroundingRectangle
from manim.scene.scene import Scene

from .. import config
from ..animation.animation import Animation
Expand All @@ -58,7 +58,7 @@ def construct(self):
from ..mobject.mobject import Mobject
from ..mobject.types.vectorized_mobject import VGroup, VMobject
from ..utils.bezier import interpolate, inverse_interpolate
from ..utils.color import GREY, YELLOW
from ..utils.color import GREY, YELLOW, ParsableManimColor
from ..utils.deprecation import deprecated
from ..utils.rate_functions import smooth, there_and_back, wiggle
from ..utils.space_ops import normalize
Expand Down Expand Up @@ -314,7 +314,7 @@ def _get_bounds(self, alpha: float) -> Tuple[float]:
lower = max(lower, 0)
return (lower, upper)

def clean_up_from_scene(self, scene: "Scene") -> None:
def clean_up_from_scene(self, scene: Scene) -> None:
super().clean_up_from_scene(scene)
for submob, start in self.get_all_families_zipped():
submob.pointwise_become_partial(start, 0, 1)
Expand Down Expand Up @@ -609,7 +609,7 @@ def __init__(
fade_out=False,
time_width=0.3,
buff: float = SMALL_BUFF,
color: Color = YELLOW,
color: ParsableManimColor = YELLOW,
run_time=1,
stroke_width=DEFAULT_STROKE_WIDTH,
**kwargs
Expand Down
16 changes: 11 additions & 5 deletions manim/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import itertools as it
import operator as op
import pathlib
import time
from functools import reduce
from typing import Any, Callable, Iterable

Expand All @@ -24,7 +23,7 @@
from ..mobject.types.image_mobject import AbstractImageMobject
from ..mobject.types.point_cloud_mobject import PMobject
from ..mobject.types.vectorized_mobject import VMobject
from ..utils.color import color_to_int_rgba
from ..utils.color import ManimColor, ParsableManimColor, color_to_int_rgba
from ..utils.family import extract_mobject_family_members
from ..utils.images import get_full_raster_image_path
from ..utils.iterables import list_difference_update
Expand Down Expand Up @@ -75,6 +74,8 @@ def __init__(
frame_height: float | None = None,
frame_width: float | None = None,
frame_rate: float | None = None,
background_color: ParsableManimColor | None = None,
background_opacity: float | None = None,
**kwargs,
):
self.background_image = background_image
Expand Down Expand Up @@ -106,9 +107,14 @@ def __init__(
frame_rate = config["frame_rate"]
self.frame_rate = frame_rate

# TODO: change this to not use kwargs.get
for attr in ["background_color", "background_opacity"]:
setattr(self, f"_{attr}", kwargs.get(attr, config[attr]))
if background_color is None:
self._background_color = ManimColor.parse(config["background_color"])
else:
self._background_color = ManimColor.parse(background_color)
if background_opacity is None:
self._background_opacity = config["background_opacity"]
else:
self._background_opacity = background_opacity

# This one is in the same boat as the above, but it doesn't have the
# same name as the corresponding key so it has to be handled on its own
Expand Down
9 changes: 0 additions & 9 deletions manim/communitycolors.py

This file was deleted.

32 changes: 17 additions & 15 deletions manim/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from enum import Enum

import numpy as np
from cloup import Context
from cloup import Context # type: ignore
from PIL.Image import Resampling

from manim.typing import Point3D

__all__ = [
"SCENE_NOT_FOUND_MESSAGE",
"CHOOSE_NUMBER_MESSAGE",
Expand Down Expand Up @@ -119,43 +121,43 @@
}

# Geometry: directions
ORIGIN: np.ndarray = np.array((0.0, 0.0, 0.0))
ORIGIN: Point3D = np.array((0.0, 0.0, 0.0))
"""The center of the coordinate system."""

UP: np.ndarray = np.array((0.0, 1.0, 0.0))
UP: Point3D = np.array((0.0, 1.0, 0.0))
"""One unit step in the positive Y direction."""

DOWN: np.ndarray = np.array((0.0, -1.0, 0.0))
DOWN: Point3D = np.array((0.0, -1.0, 0.0))
"""One unit step in the negative Y direction."""

RIGHT: np.ndarray = np.array((1.0, 0.0, 0.0))
RIGHT: Point3D = np.array((1.0, 0.0, 0.0))
"""One unit step in the positive X direction."""

LEFT: np.ndarray = np.array((-1.0, 0.0, 0.0))
LEFT: Point3D = np.array((-1.0, 0.0, 0.0))
"""One unit step in the negative X direction."""

IN: np.ndarray = np.array((0.0, 0.0, -1.0))
IN: Point3D = np.array((0.0, 0.0, -1.0))
"""One unit step in the negative Z direction."""

OUT: np.ndarray = np.array((0.0, 0.0, 1.0))
OUT: Point3D = np.array((0.0, 0.0, 1.0))
"""One unit step in the positive Z direction."""

# Geometry: axes
X_AXIS: np.ndarray = np.array((1.0, 0.0, 0.0))
Y_AXIS: np.ndarray = np.array((0.0, 1.0, 0.0))
Z_AXIS: np.ndarray = np.array((0.0, 0.0, 1.0))
X_AXIS: Point3D = np.array((1.0, 0.0, 0.0))
Y_AXIS: Point3D = np.array((0.0, 1.0, 0.0))
Z_AXIS: Point3D = np.array((0.0, 0.0, 1.0))

# Geometry: useful abbreviations for diagonals
UL: np.ndarray = UP + LEFT
UL: Point3D = UP + LEFT
"""One step up plus one step left."""

UR: np.ndarray = UP + RIGHT
UR: Point3D = UP + RIGHT
"""One step up plus one step right."""

DL: np.ndarray = DOWN + LEFT
DL: Point3D = DOWN + LEFT
"""One step down plus one step left."""

DR: np.ndarray = DOWN + RIGHT
DR: Point3D = DOWN + RIGHT
"""One step down plus one step right."""

# Geometry
Expand Down
Loading