1"""
2Idenpotent Decorators, as an extendable class
3
4Key Classes:
5- DecoratorBase : Simplifies decorations to writing a _wrap_[method/fn/class] method.
6- MetaDecorator : Adds metadata to callable, without changing the behaviour of it.
7- DataDecorator : Stacks data onto the callable, with only one wrapping function
8
9"""
10from __future__ import annotations
11import typing
12
13# ##-- types
14# isort: off
15if typing.TYPE_CHECKING:
16 from ._interface import Decorated, Decorator_p
17 from jgdv import Maybe, Ident
18 from typing import ClassVar
19# isort: on
20# ##-- end types
21
22from ._interface import Signature, Decorable, DForm_e
23from ._core import Decorator, MonotonicDec, IdempotentDec, MetaDec, DataDec
24from .mixin import Mixin
25from .proto import Proto
26from .util_decorators import MethodMaybe, FnMaybe
27
[docs]
28class DecoratorAccessor_m:
29 """ A mixin for building Decorator Accessors like DKeyed.
30 Holds a _decoration_builder class, and helps you build it
31 """
32
33 _decoration_builder : ClassVar[type[Decorator]] = DataDec
34
[docs]
35 @classmethod
36 def _build_decorator(cls, keys:list) -> Decorator_p:
37 return cls._decoration_builder(keys)
38
[docs]
39 @classmethod
40 def get_keys(cls, target:Decorated) -> list[Ident]:
41 """ Retrieve key annotations from a Decorated"""
42 dec = cls._build_decorator([])
43 return dec.get_annotations(target)