Method
_perform_cast
(
self,
key: str,
value: Any,
cast: Callable[[Any], Any] | None = None,
)
Source from the content-addressed store, hash-verified
| 121 | return file_values |
| 122 | |
| 123 | def _perform_cast( |
| 124 | self, |
| 125 | key: str, |
| 126 | value: Any, |
| 127 | cast: Callable[[Any], Any] | None = None, |
| 128 | ) -> Any: |
| 129 | if cast is None or value is None: |
| 130 | return value |
| 131 | elif cast is bool and isinstance(value, str): |
| 132 | mapping = {"true": True, "1": True, "false": False, "0": False} |
| 133 | value = value.lower() |
| 134 | if value not in mapping: |
| 135 | raise ValueError(f"Config '{key}' has value '{value}'. Not a valid bool.") |
| 136 | return mapping[value] |
| 137 | try: |
| 138 | return cast(value) |
| 139 | except (TypeError, ValueError): |
| 140 | raise ValueError(f"Config '{key}' has value '{value}'. Not a valid {cast.__name__}.") |
Tested by
no test coverage detected