Returns an instance of ClassConfigBase, which is an object factory for `cls`. In other words, instantiating the config produces an instance of `cls`, where the configured attributes will be provided as arguments to `__init__`. Example: ``` class MyClass: def
(cls: type[T])
| 1142 | |
| 1143 | |
| 1144 | def config_for_class(cls: type[T]) -> Union[Any, ClassConfigBase[T]]: |
| 1145 | """Returns an instance of ClassConfigBase, which is an object factory for `cls`. |
| 1146 | |
| 1147 | In other words, instantiating the config produces an instance of `cls`, where the configured |
| 1148 | attributes will be provided as arguments to `__init__`. |
| 1149 | |
| 1150 | Example: |
| 1151 | ``` |
| 1152 | class MyClass: |
| 1153 | def __init__(self, a: int, b: Optional[int] = None): |
| 1154 | self.a = a |
| 1155 | self.b = b |
| 1156 | |
| 1157 | def values(self): |
| 1158 | return (self.a, self.b) |
| 1159 | |
| 1160 | cfg = config_for_class(MyClass).set(a=2) |
| 1161 | |
| 1162 | # Should produce unique instances. |
| 1163 | assert cfg.instantiate() is not cfg.instantiate() |
| 1164 | |
| 1165 | # Should produce the correct values. |
| 1166 | assert cfg.instantiate().values() == cfg.instantiate().values() |
| 1167 | assert cfg.instantiate().values() == (2, None) |
| 1168 | assert cfg.set(b=3).instantiate().values() == (2, 3) |
| 1169 | ``` |
| 1170 | |
| 1171 | Args: |
| 1172 | cls: The class to configure. |
| 1173 | |
| 1174 | Returns: |
| 1175 | A Config that when instantiated, invokes `cls.__init__` based on any config fields that have |
| 1176 | been set. |
| 1177 | """ |
| 1178 | config_cls = _config_class_for_class(cls) |
| 1179 | return config_cls(klass=cls) |
| 1180 | |
| 1181 | |
| 1182 | def maybe_set_config(cfg: _ConfigBase, **kwargs) -> _ConfigBase: |