Skip to content

Rename types like RGBA_Array_Float to FloatRGBA and add types like FloatRGBA_Array #4386

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

Merged
merged 5 commits into from
Aug 12, 2025

Conversation

chopan050
Copy link
Contributor

@chopan050 chopan050 commented Aug 10, 2025

Overview: What does this pull request change?

Make the following changes:

  • X_Array_Float -> FloatX (example: RGBA_Array_Float is renamed to FloatRGBA)
  • X_Array_Int -> IntX (example: RGBA_Array_Int is renamed to IntRGBA)
  • X_Tuple_Float = tuple[float, ...] -> FloatXLike = Union[FloatX, tuple[float, ...] (example: RGBA_Tuple_Float = tuple[float, float, float, float] was changed to FloatRGBALike = Union[FloatRGBA, tuple[float, float, float, float]]. This is for consistency with types such as Point3DLike, which are unions.)
  • X_Tuple_Int = tuple[int, ...] -> IntXLike = Union[IntX, tuple[int, ...]

in order to add some color array types:

  • FloatRGBA_Array is a NumPy array of shape (M, 4) containing M rows representing RGBA colors.
  • FloatRGBALike_Array is anything which can be converted to a FloatRGBA_Array, including lists of colors, for example.
  • FloatRGB_Array and FloatRGBLikeArray are the same, but for RGB colors.

and properly type multiple parameters, returned values and other variables which correspond to NumPy arrays of colors.

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

Many parameters, returned values and other variables around the source code were 2D NumPy arrays of multiple colors and their type hints were incorrect. Specifically, npt.NDArray[RGBA_Array_Float] is invalid, since RGBA_Array_Float is not really a valid or correct dtype in this case (it should be a float). This indicates that we need type aliases for arrays of colors.

However, the current names weren't ideal for this task, because, if we have RGBA_Array_Float for a single color, its corresponding type alias for array of colors would be RGBA_Array_Float_Array, which is a strange name: it's too long and contains the word Array twice, which is confusing. Therefore, I also needed to rename those aliases.

Links to added or changed documentation pages

There are too many type changes around the code, so listing all of them is not very practical. Instead, I'll just link the typing webpage:
https://manimce--4386.org.readthedocs.build/en/4386/reference/manim.typing.html

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

@chopan050 chopan050 added refactor Refactor or redesign of existing code typehints For adding/discussing typehints needs discussion Things which needs to be discussed before implemented. labels Aug 10, 2025
@github-project-automation github-project-automation bot moved this to 🆕 New in Dev Board Aug 10, 2025

def pos_to_rgb(pos: np.ndarray) -> tuple[float, float, float, float]:
def pos_to_rgb(pos: Point3D) -> FloatRGB:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that, although the return value was previously typed as a tuple of 4 floats, the code suggests that it should be some array of 3 floats instead.

Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

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

Thanks, these refactors do let our types appear way more readable; I like it!

I've pushed one commit to fix the ReST class references, please feel free to take a look (or just trust me) and merge. 🚀

@github-project-automation github-project-automation bot moved this from 🆕 New to 👍 To be merged in Dev Board Aug 12, 2025
@chopan050
Copy link
Contributor Author

I've pushed one commit to fix the ReST class references

Thanks a lot for that! I just checked the typing docs and they're looking good! I'll merge this PR.

@chopan050 chopan050 merged commit a56c06c into ManimCommunity:main Aug 12, 2025
21 checks passed
@github-project-automation github-project-automation bot moved this from 👍 To be merged to ✅ Done in Dev Board Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs discussion Things which needs to be discussed before implemented. refactor Refactor or redesign of existing code typehints For adding/discussing typehints
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants