Skip to content

Commit

Permalink
docs: update typing guidelines (ManimCommunity#3704)
Browse files Browse the repository at this point in the history
* Update typing guidelines

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix formatting

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
  • Loading branch information
JasonGrace2282 committed Apr 20, 2024
1 parent 471ce80 commit a8f8730
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions docs/source/contributing/docs/typings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ https://realpython.com/python-type-checking/#hello-types.
Typing standards
~~~~~~~~~~~~~~~~

Manim uses `mypy`_ to type check its codebase. You will find a list of
configuration values in the ``mypy.ini`` configuration file.

Manim uses `mypy`_ to type check its codebase. You will find a list of configuration values in the ``mypy.ini`` configuration file.
To be able to use the newest typing features not available in the lowest
supported Python version, make use of `typing_extensions`_.

Expand Down Expand Up @@ -91,6 +89,32 @@ Typing guidelines
* Use ``typing.Iterable`` whenever the function works with *any* iterable, not a specific type.

* Prefer ``numpy.typing.NDArray`` over ``numpy.ndarray``

.. code:: py
import numpy as np
if TYPE_CHECKING:
import numpy.typing as npt
def foo() -> npt.NDArray[float]:
return np.array([1, 0, 1])
* If a method returns ``self``, use ``typing_extensions.Self``.

.. code:: py
if TYPE_CHECKING:
from typing_extensions import Self
class CustomMobject:
def set_color(self, color: ManimColor) -> Self:
...
return self
* If the function returns a container of a specific length each time, consider using ``tuple`` instead of ``list``.

.. code:: py
Expand Down

0 comments on commit a8f8730

Please sign in to comment.