mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
Use descriptors to bind SceneSections
This commit is contained in:
parent
560ca7fe85
commit
db26fe6e5e
2 changed files with 6 additions and 3 deletions
|
|
@ -153,9 +153,6 @@ class Scene:
|
|||
# we can't care about the actual value of the order
|
||||
# because that would break files with multiple scenes that have sections
|
||||
sections.sort(key=lambda x: x.order)
|
||||
# turn them into bound methods
|
||||
for section in sections:
|
||||
section.func = section.func.__get__(self, type(self))
|
||||
return sections
|
||||
|
||||
# Only these methods should touch the camera
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import types
|
||||
from collections.abc import Callable
|
||||
from typing import ClassVar, Generic, ParamSpec, TypeVar, final, overload
|
||||
|
||||
|
|
@ -79,6 +80,11 @@ class SceneSection(Generic[P, T]):
|
|||
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T:
|
||||
return self.func(*args, **kwargs)
|
||||
|
||||
# bind func to the Scene
|
||||
def __get__(self, instance: None, _owner: type) -> SceneSection[P, T]:
|
||||
self.func = types.MethodType(self.func, instance)
|
||||
return self
|
||||
|
||||
|
||||
@overload
|
||||
def section(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue