Skip to content

Commit 8d7bb13

Browse files
Add decorator
1 parent 31df6d0 commit 8d7bb13

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

manim/utils/decorators.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING, TypeVar
4+
5+
if TYPE_CHECKING:
6+
from collections.abc import Callable
7+
8+
from typing_extensions import ParamSpec
9+
10+
P = ParamSpec("P")
11+
T = TypeVar("T")
12+
13+
14+
def internal(f: Callable[P, T]) -> Callable[P, T]:
15+
"""
16+
This decorator marks a function as internal
17+
by adding a warning to the docstring of the object.
18+
19+
Note that usage on a method starting with an underscore
20+
has no effect, as sphinx does not document such methods
21+
22+
.. code-block:: python
23+
24+
@internal
25+
def some_private_method(self):
26+
# does some private stuff
27+
...
28+
29+
30+
@internal # does not do anything, don't use
31+
def _my_second_private_method(self): ...
32+
"""
33+
doc: str = f.__doc__ if f.__doc__ is not None else ""
34+
newblockline = "\n "
35+
directive = f".. warning::{newblockline}"
36+
directive += newblockline.join(
37+
(
38+
"This method is designed for internal use",
39+
"and may not stay the same in future versions of Manim",
40+
)
41+
)
42+
f.__doc__ = f"{directive}\n\n{doc}"
43+
return f

0 commit comments

Comments
 (0)