mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Update the types in decorator methods using @wraps
This is method to address issues flagged by pyright
This commit is contained in:
parent
cde709fcfa
commit
711438f625
1 changed files with 14 additions and 8 deletions
|
@ -48,11 +48,12 @@ from manimlib.utils.space_ops import rotation_matrix_transpose
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Callable, Iterable, Iterator, Union, Tuple, Optional
|
from typing import Callable, Iterable, Iterator, Union, Tuple, Optional, TypeVar, Any
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
from manimlib.typing import ManimColor, Vect3, Vect4, Vect3Array, UniformDict, Self
|
from manimlib.typing import ManimColor, Vect3, Vect4, Vect3Array, UniformDict, Self
|
||||||
from moderngl.context import Context
|
from moderngl.context import Context
|
||||||
|
|
||||||
|
T = TypeVar('T')
|
||||||
TimeBasedUpdater = Callable[["Mobject", float], "Mobject" | None]
|
TimeBasedUpdater = Callable[["Mobject", float], "Mobject" | None]
|
||||||
NonTimeUpdater = Callable[["Mobject"], "Mobject" | None]
|
NonTimeUpdater = Callable[["Mobject"], "Mobject" | None]
|
||||||
Updater = Union[TimeBasedUpdater, NonTimeUpdater]
|
Updater = Union[TimeBasedUpdater, NonTimeUpdater]
|
||||||
|
@ -164,20 +165,23 @@ class Mobject(object):
|
||||||
mob.note_changed_data()
|
mob.note_changed_data()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def affects_data(func: Callable):
|
@staticmethod
|
||||||
|
def affects_data(func: Callable[..., T]) -> Callable[..., T]:
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
func(self, *args, **kwargs)
|
result = func(self, *args, **kwargs)
|
||||||
self.note_changed_data()
|
self.note_changed_data()
|
||||||
|
return result
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
def affects_family_data(func: Callable):
|
@staticmethod
|
||||||
|
def affects_family_data(func: Callable[..., T]) -> Callable[..., T]:
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
func(self, *args, **kwargs)
|
result = func(self, *args, **kwargs)
|
||||||
for mob in self.family_members_with_points():
|
for mob in self.family_members_with_points():
|
||||||
mob.note_changed_data()
|
mob.note_changed_data()
|
||||||
return self
|
return result
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
# Only these methods should directly affect points
|
# Only these methods should directly affect points
|
||||||
|
@ -578,7 +582,8 @@ class Mobject(object):
|
||||||
|
|
||||||
# Copying and serialization
|
# Copying and serialization
|
||||||
|
|
||||||
def stash_mobject_pointers(func: Callable):
|
@staticmethod
|
||||||
|
def stash_mobject_pointers(func: Callable[..., T]) -> Callable[..., T]:
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
uncopied_attrs = ["parents", "target", "saved_state"]
|
uncopied_attrs = ["parents", "target", "saved_state"]
|
||||||
|
@ -1863,7 +1868,8 @@ class Mobject(object):
|
||||||
|
|
||||||
# Operations touching shader uniforms
|
# Operations touching shader uniforms
|
||||||
|
|
||||||
def affects_shader_info_id(func: Callable):
|
@staticmethod
|
||||||
|
def affects_shader_info_id(func: Callable[..., T]) -> Callable[..., T]:
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
result = func(self, *args, **kwargs)
|
result = func(self, *args, **kwargs)
|
||||||
|
|
Loading…
Add table
Reference in a new issue