Skip to content

Generate rgbas array in mobject#4676

Open
GoThrones wants to merge 6 commits intoManimCommunity:mainfrom
GoThrones:generate_rgbas_array_in_VMobject
Open

Generate rgbas array in mobject#4676
GoThrones wants to merge 6 commits intoManimCommunity:mainfrom
GoThrones:generate_rgbas_array_in_VMobject

Conversation

@GoThrones
Copy link
Copy Markdown
Contributor

@GoThrones GoThrones commented Apr 4, 2026

Overview: What does this pull request change?

This PR improves the docstring of the method: generate_rgbas_array in VMobject class. Also improves names of some of the variables in that method.

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

@GoThrones GoThrones force-pushed the generate_rgbas_array_in_VMobject branch from 2e10826 to ac2c360 Compare April 4, 2026 19:23
Copy link
Copy Markdown
Member

@chopan050 chopan050 left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! It's nice to have a more descriptive docstring and variable names.

I left some change requests:

Comment on lines 224 to 225
color: ParsableManimColor | Iterable[ManimColor] | None,
opacity: float | Iterable[float],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please also fix the parameter typehints? color can be an iterable of any ParsableManimColors, not strictly ManimColors. opacity can also be None, given the code below. Technically, both iterables could also contain None values, but I don't think it's strictly necessary to include that last thing in the typehint...

Suggested change
color: ParsableManimColor | Iterable[ManimColor] | None,
opacity: float | Iterable[float],
color: ParsableManimColor | Iterable[ParsableManimColor] | None,
opacity: float | Iterable[float] | None,

Copy link
Copy Markdown
Contributor Author

@GoThrones GoThrones Apr 17, 2026

Choose a reason for hiding this comment

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

Thanks for your suggestions. I've rectified the code to reflect those changes.

one color was passed in, a second slightly light color
will automatically be added for the gradient
) -> FloatRGBA_Array:
"""Returns a 2D array of shape (N,4) where N is the number of colors in the list
Copy link
Copy Markdown
Member

@chopan050 chopan050 Apr 16, 2026

Choose a reason for hiding this comment

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

There are some conventions which, admittedly, many of our current docstrings do not follow, so it would be nice to start enforcing them when improving the documentation. According to PEP 257:

The docstring is a phrase ending in a period. It prescribes the function or method’s effect as a command (“Do this”, “Return that”), not as a description; e.g. don’t write “Returns the pathname …”.

Suggested change
"""Returns a 2D array of shape (N,4) where N is the number of colors in the list
"""Return a 2D array of shape (N,4) where N is the number of colors in the list

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was aware of that convention. However, I must admit that whenever I see a new function/method, I question: What does this function do?
And the obvious way that i see the answer forming is: """This method/function returns...
or simply: """Returns... """

I have never found it intuitive to read the docstring that start like this: """Return this, or do that. """

Many of the functions/methods in manimce sourcecode, in many other files, already has the style: """Returns... """ or """Gets... """. So, maybe I'm not alone in thinking that it's better to read a function's/method's docstring as: """Returns... """ instead of """Return...".

Also, I'm wondering that is it really necessary or even desirable to follow this particular convention prescribed by PEP 257 ? And if yes, then to what end ?

Comment on lines +230 to +234
Parameters
----------
color: Can be a single color, or a tuple/list of colors, or any of the ParsableManimColor.

opacity: Can either be a float, or a tuple/list or any iterable of floats.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Notice that, according to the NumPy style guide which we want to follow, each parameter name must start at the same indentation level as the Parameters title, and the description of each parameter must start in a new line and with one more indentation level. Instead of:

Parameters
----------
    parameter1: Description 1
    parameter2: Description 2

it should be:

Parameters
----------
parameter1
    Description 1
parameter2
    Description 2

By formatting the docstring correctly, we can automatically generate correct documentation for the method. See the documentation for VMobject.generate_rgbas_array() which was automatically generated for this PR after you made it. Currently, the Parameters and Returns sections are duplicated because the Parameters section could not be parsed correctly.

Notice that the NumPy style guide mentions adding the typehint next to each parameter name in the docstring. However, we're not doing that in the docstring: it is enough with typehinting the parameters in the function declaration, and our documentation process captures those typehints and adds them into the Parameters section anyways.

Suggested change
Parameters
----------
color: Can be a single color, or a tuple/list of colors, or any of the ParsableManimColor.
opacity: Can either be a float, or a tuple/list or any iterable of floats.
Parameters
----------
color
A single color, an iterable of multiple colors, or `None` (which is replaced
with `BLACK`).
opacity
The opacity of a color as a number between 0.0 and 1.0, an iterable of multiple
color opacities, or `None` (which is replaced with 0.0).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your suggestions.
I've rectified the code in accordance with your suggestion, with some minor alterations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants