MCPcopy Index your code
hub / github.com/python/cpython / force_color

Function force_color

Lib/test/support/__init__.py:3023–3040  ·  view source on GitHub ↗
(color: bool)

Source from the content-addressed store, hash-verified

3021
3022@contextlib.contextmanager
3023def force_color(color: bool):
3024 import _colorize
3025 from .os_helper import EnvironmentVarGuard
3026
3027 if color:
3028 try:
3029 import _pyrepl # noqa: F401
3030 except ModuleNotFoundError:
3031 # Can't force enable color without _pyrepl, so just skip.
3032 raise unittest.SkipTest("_pyrepl is missing")
3033
3034 with (
3035 swap_attr(_colorize, "can_colorize", lambda *, file=None: color),
3036 EnvironmentVarGuard() as env,
3037 ):
3038 env.unset("FORCE_COLOR", "NO_COLOR", "PYTHON_COLORS")
3039 env.set("FORCE_COLOR" if color else "NO_COLOR", "1")
3040 yield
3041
3042
3043def force_colorized(func):

Calls 4

swap_attrFunction · 0.85
EnvironmentVarGuardClass · 0.85
unsetMethod · 0.80
setMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…