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

Adding type annotations to manim.utils.* #3999

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

Conversation

henrikmidtiby
Copy link
Contributor

Overview: What does this pull request change?

The PR adds type annotations to some of the elements in manim/utils

Motivation and Explanation: Why and how do your changes improve the library?

Type annotations are a good thing.

Further Information and Comments

I have chosen to go for smaller PR regarding adding type annotations.
The endeavor of #3981 is a bit frightening...

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

@@ -54,10 +56,12 @@
@overload
def bezier(
points: Sequence[Point3D_Array],
) -> Callable[[float | ColVector], Point3D_Array]: ...
) -> Callable[[float | ColVector], Point3D | Point3D_Array]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
def interpolate(start: Point3D, end: Point3D, alpha: float) -> Point3D: ...
def interpolate(
start: InternalPoint3D, end: InternalPoint3D, alpha: float
) -> Point3D: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
def interpolate(start: Point3D, end: Point3D, alpha: ColVector) -> Point3D_Array: ...
def interpolate(
start: InternalPoint3D, end: InternalPoint3D, alpha: ColVector
) -> Point3D_Array: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
@@ -1099,10 +1115,12 @@


@overload
def mid(start: Point3D, end: Point3D) -> Point3D: ...
def mid(start: InternalPoint3D, end: InternalPoint3D) -> Point3D: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
def inverse_interpolate(start: float, end: float, value: Point3D) -> Point3D: ...
def inverse_interpolate(
start: float, end: float, value: InternalPoint3D
) -> InternalPoint3D: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
def inverse_interpolate(start: Point3D, end: Point3D, value: Point3D) -> Point3D: ...
def inverse_interpolate(
start: InternalPoint3D, end: InternalPoint3D, value: InternalPoint3D
) -> Point3D: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
manim/utils/color/core.py Fixed Show fixed Hide fixed
manim/scene/scene_file_writer.py Fixed Show fixed Hide fixed
manim/scene/scene_file_writer.py Fixed Show fixed Hide fixed


def clip(a, min_a, max_a):
@overload
def clip(a: float, min_a: float, max_a: float) -> float: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.


@overload
def clip(a: str, min_a: str, max_a: str) -> str: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
@henrikmidtiby
Copy link
Contributor Author

@JasonGrace2282 Would you take a look at this PR?

@JasonGrace2282
Copy link
Member

I'll take a look when I find the time.

@@ -2,20 +2,26 @@

import itertools as it

from manim.mobject.mobject import Mobject

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.utils.family_ops
, as the
definition
of Mobject occurs after the cyclic
import
of manim.utils.family_ops.
'Mobject' may not be defined if module
manim.mobject.mobject
is imported before module
manim.utils.family_ops
, as the
definition
of Mobject occurs after the cyclic
import
of manim.utils.family_ops.

def handle_caching_play(func: Callable[..., None]):
from manim.scene.scene import Scene

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.utils.caching
, as the
definition
of Scene occurs after the cyclic
import
of manim.utils.caching.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.utils.caching
, as the
definition
of Scene occurs after the cyclic
import
of manim.utils.caching.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.utils.caching
, as the
definition
of Scene occurs after the cyclic
import
of manim.utils.caching.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.utils.caching
, as the
definition
of Scene occurs after the cyclic
import
of manim.utils.caching.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.utils.caching
, as the
definition
of Scene occurs after the cyclic
import
of manim.utils.caching.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.utils.caching
, as the
definition
of Scene occurs after the cyclic
import
of manim.utils.caching.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.utils.caching
, as the
definition
of Scene occurs after the cyclic
import
of manim.utils.caching.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.utils.caching
, as the
definition
of Scene occurs after the cyclic
import
of manim.utils.caching.
'Scene' may not be defined if module
manim.scene.scene
is imported before module
manim.utils.caching
, as the
definition
of Scene occurs after the cyclic
import
of manim.utils.caching.
__all__ = ["scene_classes_from_file"]


def get_module(file_name: Path):
def get_module(file_name: Path) -> types.ModuleType:

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
@henrikmidtiby henrikmidtiby mentioned this pull request Nov 14, 2024
22 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.

2 participants