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 1 commit
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
5 changes: 3 additions & 2 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
Iterable,
TypeVar,
Literal,
Self
Self,
Never
)

import numpy as np
Expand Down Expand Up @@ -2755,7 +2756,7 @@ def construct(self):
return self

# Errors
def throw_error_if_no_points(self) -> None:
def throw_error_if_no_points(self) -> None | Never:
Copy link
Member

@Viicos Viicos Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Never is used correctly here 🤔 It is usually not the way to type hint functions that can possibly raise

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then how should one type a function that is supposed to raise an Exception?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually a function that always raise uses NoReturn, but if it raises conditionally then you can't really tell with type hints (some docstring conventions such as the one from Google have a dedicated section).

You would probably want to use NoReturn | None, but iirc mypy isn't happy with it, and having this doesn't add any value to the return type imo 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So then I'll just keep it as -> None in my next push :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I would love to continue contributing in typing but I'm still concerned about #3086 (comment). Unfortunately I'm missing time currently, but I'll see if I can still contribute a bit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be fine for now, there is not that much left to do, we already got the Colors out of the windows now and what's left is currently not doable because of recursive imports so the next thing that is merged will be this PR and probably nothing else so we have a clean slate of manim that we can work on for the other PRs which makes a lot more sense then.

if self.has_no_points():
caller_name = sys._getframe(1).f_code.co_name
raise Exception(
Expand Down
20 changes: 12 additions & 8 deletions manim/mobject/three_d/three_d_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,43 @@


import numpy as np
from typing import Literal, TYPE_CHECKING

from manim.constants import ORIGIN, UP
from manim.utils.space_ops import get_unit_normal

if TYPE_CHECKING:
from manim.typing import Point3D, Vector

def get_3d_vmob_gradient_start_and_end_points(vmob):

def get_3d_vmob_gradient_start_and_end_points(vmob) -> tuple[Point3D, Point3D]:
return (
get_3d_vmob_start_corner(vmob),
get_3d_vmob_end_corner(vmob),
)


def get_3d_vmob_start_corner_index(vmob):
def get_3d_vmob_start_corner_index(vmob) -> Literal[0]:
return 0


def get_3d_vmob_end_corner_index(vmob):
def get_3d_vmob_end_corner_index(vmob) -> int:
return ((len(vmob.points) - 1) // 6) * 3


def get_3d_vmob_start_corner(vmob):
def get_3d_vmob_start_corner(vmob) -> Point3D:
if vmob.get_num_points() == 0:
return np.array(ORIGIN)
return vmob.points[get_3d_vmob_start_corner_index(vmob)]


def get_3d_vmob_end_corner(vmob):
def get_3d_vmob_end_corner(vmob) -> Point3D:
if vmob.get_num_points() == 0:
return np.array(ORIGIN)
return vmob.points[get_3d_vmob_end_corner_index(vmob)]


def get_3d_vmob_unit_normal(vmob, point_index):
def get_3d_vmob_unit_normal(vmob, point_index: int) -> Vector:
n_points = vmob.get_num_points()
if len(vmob.get_anchors()) <= 2:
return np.array(UP)
Expand All @@ -63,9 +67,9 @@ def get_3d_vmob_unit_normal(vmob, point_index):
return unit_normal


def get_3d_vmob_start_corner_unit_normal(vmob):
def get_3d_vmob_start_corner_unit_normal(vmob) -> Vector:
return get_3d_vmob_unit_normal(vmob, get_3d_vmob_start_corner_index(vmob))


def get_3d_vmob_end_corner_unit_normal(vmob):
def get_3d_vmob_end_corner_unit_normal(vmob) -> Vector:
return get_3d_vmob_unit_normal(vmob, get_3d_vmob_end_corner_index(vmob))
Loading