Generate rgbas array in mobject#4676
Conversation
2e10826 to
ac2c360
Compare
chopan050
left a comment
There was a problem hiding this comment.
Thanks for your contribution! It's nice to have a more descriptive docstring and variable names.
I left some change requests:
| color: ParsableManimColor | Iterable[ManimColor] | None, | ||
| opacity: float | Iterable[float], |
There was a problem hiding this comment.
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...
| color: ParsableManimColor | Iterable[ManimColor] | None, | |
| opacity: float | Iterable[float], | |
| color: ParsableManimColor | Iterable[ParsableManimColor] | None, | |
| opacity: float | Iterable[float] | None, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 …”.
| """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 |
There was a problem hiding this comment.
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 ?
| 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. |
There was a problem hiding this comment.
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.
| 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). |
There was a problem hiding this comment.
Thanks for your suggestions.
I've rectified the code in accordance with your suggestion, with some minor alterations.
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