Use descriptors to bind SceneSections

This commit is contained in:
JasonGrace2282 2024-09-02 12:39:53 -04:00
commit db26fe6e5e
No known key found for this signature in database
GPG key ID: 8D61FE3F93FB15FA
2 changed files with 6 additions and 3 deletions

View file

@ -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

View file

@ -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(