21from __future__
import annotations
23__all__ = (
"ConfigurableActionField",)
25from typing
import Any, overload
31from .
import ConfigurableAction, ActionTypeVar
35 """`ConfigurableActionField` is a subclass of `~lsst.pex.config.Field` that
36 allows a single `ConfigurableAction` (or a subclass of thus) to be
37 assigned to it. The `ConfigurableAction`
is then accessed through this
38 field
for further configuration.
40 Any configuration that
is done prior to reasignment to a new
41 `ConfigurableAction`
is forgotten.
50 value: ActionTypeVar | type[ActionTypeVar],
52 label: str =
"assignment"
55 raise FieldValidationError(self, instance,
56 "Cannot modify a frozen Config")
57 name = _joinNamePath(prefix=instance._name, name=self.
name)
59 if not isinstance(value, self.dtype)
and not issubclass(value, self.dtype):
60 msg = f
"Value {value} is of incorrect type {_typeStr(value)}. Expected {_typeStr(self.dtype)}"
61 raise FieldValidationError(self, instance, msg)
66 if isinstance(value, self.dtype):
67 instance._storage[self.
name] = type(value)(__name=name, __at=at,
68 __label=label, **value._storage)
70 instance._storage[self.
name] = value(__name=name, __at=at, __label=label)
71 history = instance._history.setdefault(self.
name, [])
72 history.append((
"config value set", at, label))
76 self, instance: None, owner: Any =
None, at: Any =
None, label: str =
"default"
77 ) ->
"ConfigurableActionField[ActionTypeVar]":
82 self, instance:
"Config", owner: Any =
None, at: Any =
None, label: str =
"default"
86 def __get__(self, instance, owner=None, at=None, label="default"):
87 result = super().
__get__(instance, owner)
88 if instance
is not None:
91 result.identity = self.
name
94 def save(self, outfile, instance):
100 fullname = _joinNamePath(instance._name, self.
name)
101 outfile.write(f
"{fullname}={_typeStr(value)}\n")
102 super().
save(outfile, instance)
104 def __init__(self, doc, dtype=ConfigurableAction, default=None, check=None, deprecated=None):
105 if not issubclass(dtype, ConfigurableAction):
106 raise ValueError(
"dtype must be a subclass of ConfigurableAction")
107 super().
__init__(doc=doc, dtype=dtype, default=default, check=check, deprecated=deprecated)
def save(self, outfile, instance)
"ConfigurableActionField[ActionTypeVar]" __get__(self, None instance, Any owner=None, Any at=None, str label="default")
def __get__(self, instance, owner=None, at=None, label="default")
Any __get__(self, "Config" instance, Any owner=None, Any at=None, str label="default")
def __init__(self, doc, dtype=ConfigurableAction, default=None, check=None, deprecated=None)
None __set__(self, Config instance, ActionTypeVar|type[ActionTypeVar] value, Any at=None, str label="assignment")