Convert a string representation of truth to True or False. True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if 'val' is anything else. .. note:: Copied from distutils.util.
(val: str)
| 2101 | |
| 2102 | |
| 2103 | def _strtobool(val: str) -> bool: |
| 2104 | """Convert a string representation of truth to True or False. |
| 2105 | |
| 2106 | True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values |
| 2107 | are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if |
| 2108 | 'val' is anything else. |
| 2109 | |
| 2110 | .. note:: Copied from distutils.util. |
| 2111 | """ |
| 2112 | val = val.lower() |
| 2113 | if val in ("y", "yes", "t", "true", "on", "1"): |
| 2114 | return True |
| 2115 | elif val in ("n", "no", "f", "false", "off", "0"): |
| 2116 | return False |
| 2117 | else: |
| 2118 | raise ValueError(f"invalid truth value {val!r}") |
| 2119 | |
| 2120 | |
| 2121 | @lru_cache(maxsize=50) |
no outgoing calls