MCPcopy
hub / github.com/pytest-dev/pytest / _strtobool

Function _strtobool

src/_pytest/config/__init__.py:2103–2118  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2101
2102
2103def _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)

Callers 3

_get_auto_indentMethod · 0.90
test_strtoboolFunction · 0.90
_getini_iniMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_strtoboolFunction · 0.72