Config value for loading config from a string Interpretation is deferred until it is loaded into the trait. Subclass of str for backward compatibility. This class is only used for values that are not listed in the configurable classes. When config is loaded, `trait.from_strin
| 388 | |
| 389 | |
| 390 | class DeferredConfigString(str, DeferredConfig): |
| 391 | """Config value for loading config from a string |
| 392 | |
| 393 | Interpretation is deferred until it is loaded into the trait. |
| 394 | |
| 395 | Subclass of str for backward compatibility. |
| 396 | |
| 397 | This class is only used for values that are not listed |
| 398 | in the configurable classes. |
| 399 | |
| 400 | When config is loaded, `trait.from_string` will be used. |
| 401 | |
| 402 | If an error is raised in `.from_string`, |
| 403 | the original string is returned. |
| 404 | |
| 405 | .. versionadded:: 5.0 |
| 406 | """ |
| 407 | |
| 408 | def get_value(self, trait: TraitType[t.Any, t.Any]) -> t.Any: |
| 409 | """Get the value stored in this string""" |
| 410 | s = str(self) |
| 411 | try: |
| 412 | return trait.from_string(s) |
| 413 | except Exception: |
| 414 | # exception casting from string, |
| 415 | # let the original string lie. |
| 416 | # this will raise a more informative error when config is loaded. |
| 417 | return s |
| 418 | |
| 419 | def __repr__(self) -> str: |
| 420 | return f"{self.__class__.__name__}({self._super_repr()})" |
| 421 | |
| 422 | |
| 423 | class DeferredConfigList(t.List[t.Any], DeferredConfig): |
no outgoing calls
no test coverage detected
searching dependent graphs…