Skip to content

Commit 68fd77f

Browse files
Add decorator
1 parent 31df6d0 commit 68fd77f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

manim/utils/decorators.py

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

0 commit comments

Comments
 (0)