Alternate constructor for 'baby' DataProxies used as sub-dict values. Allows creating standalone DataProxy objects while also letting subclasses like `.Config` define their own ``__init__`` without muddling the two. :param dict data: This partic
(
cls,
data: Dict[str, Any],
root: Optional["DataProxy"] = None,
keypath: Tuple[str, ...] = tuple(),
)
| 75 | |
| 76 | @classmethod |
| 77 | def from_data( |
| 78 | cls, |
| 79 | data: Dict[str, Any], |
| 80 | root: Optional["DataProxy"] = None, |
| 81 | keypath: Tuple[str, ...] = tuple(), |
| 82 | ) -> "DataProxy": |
| 83 | """ |
| 84 | Alternate constructor for 'baby' DataProxies used as sub-dict values. |
| 85 | |
| 86 | Allows creating standalone DataProxy objects while also letting |
| 87 | subclasses like `.Config` define their own ``__init__`` without |
| 88 | muddling the two. |
| 89 | |
| 90 | :param dict data: |
| 91 | This particular DataProxy's personal data. Required, it's the Data |
| 92 | being Proxied. |
| 93 | |
| 94 | :param root: |
| 95 | Optional handle on a root DataProxy/Config which needs notification |
| 96 | on data updates. |
| 97 | |
| 98 | :param tuple keypath: |
| 99 | Optional tuple describing the path of keys leading to this |
| 100 | DataProxy's location inside the ``root`` structure. Required if |
| 101 | ``root`` was given (and vice versa.) |
| 102 | |
| 103 | .. versionadded:: 1.0 |
| 104 | """ |
| 105 | obj = cls() |
| 106 | obj._set(_config=data) |
| 107 | obj._set(_root=root) |
| 108 | obj._set(_keypath=keypath) |
| 109 | return obj |
| 110 | |
| 111 | def __getattr__(self, key: str) -> Any: |
| 112 | # NOTE: due to default Python attribute-lookup semantics, "real" |