Add type annotations for most of camera and mobject.graphing#4125
Add type annotations for most of camera and mobject.graphing#4125chopan050 merged 38 commits intoManimCommunity:mainfrom
camera and mobject.graphing#4125Conversation
updates: - [github.com/astral-sh/ruff-pre-commit: v0.9.1 → v0.9.2](astral-sh/ruff-pre-commit@v0.9.1...v0.9.2)
6b8f27d to
f767e8a
Compare
| from ..utils.space_ops import angle_of_vector | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ..mobject.types.image_mobject import AbstractImageMobject |
Check failure
Code scanning / CodeQL
Module-level cyclic import
| return self.point_to_coords(point) | ||
|
|
||
| @staticmethod | ||
| def _origin_shift(axis_range: Sequence[float]) -> float: ... |
Check notice
Code scanning / CodeQL
Statement has no effect
| from manim.typing import StrPath | ||
| from manim.typing import PixelArray, StrPath | ||
|
|
||
| from ...camera.moving_camera import MovingCamera |
Check failure
Code scanning / CodeQL
Module-level cyclic import
| self.display_funcs: dict[ | ||
| type[Mobject], Callable[[list[Mobject], PixelArray], Any] | ||
| ] = { | ||
| VMobject: self.display_multiple_vectorized_mobjects, # type: ignore[dict-item] |
There was a problem hiding this comment.
I ended up using a type ignore statement here.
| assert isinstance(label_mob, VMobject) | ||
| label_mobs.add(label_mob) | ||
| parts.braces = braces | ||
| parts.labels = label_mobs | ||
| parts.label_kwargs = { | ||
| parts.braces = braces # type: ignore[attr-defined] | ||
| parts.labels = label_mobs # type: ignore[attr-defined] | ||
| parts.label_kwargs = { # type: ignore[attr-defined] |
There was a problem hiding this comment.
Here I chose to use an assert statement and a few type ignores.
chopan050
left a comment
There was a problem hiding this comment.
I left some suggestions I missed. Hopefully these will be the last 🙏🏼
| def __init__(self, function, x_range=None, color=YELLOW, **kwargs): | ||
| def __init__( | ||
| self, | ||
| function: Callable[[float], Any], |
There was a problem hiding this comment.
It's probably fine for now that function returns Any instead of float for compatibility with the parent class' function attribute. In a subsequent PR, there should be a rewrite such that FunctionGraph.function is different from ParametricFunction.function.
| unit_decimal_places=decimal_number_config["num_decimal_places"], | ||
| ) | ||
|
|
||
| self.add_labels( |
There was a problem hiding this comment.
It's strange that this wasn't autocollapsed by pre-commit into a single line like this:
self.add_labels(dict(zip(tick_range, custom_labels)))Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
| # TODO: I think the method should be able to return more than just a single point. | ||
| # E.g. see the implementation of it on line 2065. |
There was a problem hiding this comment.
I think that this function (or rather its descendants) should be able to return more than a single point.
There was a problem hiding this comment.
That's actually correct. The Axes.coords_to_points() method I optimized in #3286 also uses that behavior. Thanks for reminding me of it.
This behavior is probably too complex to type for now, so let's leave the TODO there.
|
I took another look at the code and found a number of things that I wanted to change. See the last four commits. |
camera and mobject.graphing
| self.custom_labels = custom_labels | ||
|
|
||
| @overload | ||
| def function(self, value: float) -> float: ... |
Check notice
Code scanning / CodeQL
Statement has no effect
| def function(self, value: float) -> float: ... | ||
|
|
||
| @overload | ||
| def function(self, value: np.ndarray) -> np.ndarray: ... |
Check notice
Code scanning / CodeQL
Statement has no effect
Overview: What does this pull request change?
Adding type annotations for files in mobject/graphing/.* and camera/.*