Skip to content

Commit

Permalink
Add property to inject_self.cached
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Aug 4, 2024
1 parent 5b85b4e commit 969527b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions stgpytools/types/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ class cached(Generic[T0, P0, R0], inject_self_base[T0, P0, R0]):
Once ``self`` is constructed, it will be reused.
"""

class property(Generic[T0, R0]):
def __init__(self, function: Callable[[T0], R0]) -> None:
self.function = inject_self(function)

def __get__(
self, class_obj: type[T0] | T0 | None, class_type: type[T0] | type[type[T0]] # type: ignore
) -> R0:
return self.function.__get__(class_obj, class_type)()

class init_kwargs(Generic[T0, P0, R0], inject_self_base[T0, P0, R0]):
"""
Wrap a method so it always has a constructed ``self`` provided to it.
Expand Down

0 comments on commit 969527b

Please sign in to comment.