From 64dc5f139445018fc8fa0ce8849130f874324cac Mon Sep 17 00:00:00 2001 From: Olivier Philippon Date: Wed, 11 May 2022 11:17:40 +0100 Subject: [PATCH] [console][typing] Extract color-system-as-a-string to a type literal --- rich/console.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/rich/console.py b/rich/console.py index 2159d3c1..1c79352b 100644 --- a/rich/console.py +++ b/rich/console.py @@ -522,14 +522,19 @@ def _is_jupyter() -> bool: # pragma: no cover return False # Other type (?) -COLOR_SYSTEMS = { +ConsoleColorSystem = Literal["auto", "standard", "256", "truecolor", "windows"] + + +COLOR_SYSTEMS: Dict[ConsoleColorSystem, ColorSystem] = { "standard": ColorSystem.STANDARD, "256": ColorSystem.EIGHT_BIT, "truecolor": ColorSystem.TRUECOLOR, "windows": ColorSystem.WINDOWS, } -_COLOR_SYSTEMS_NAMES = {system: name for name, system in COLOR_SYSTEMS.items()} +_COLOR_SYSTEMS_NAMES: Dict[ColorSystem, ConsoleColorSystem] = { + system: name for name, system in COLOR_SYSTEMS.items() +} @dataclass @@ -619,9 +624,7 @@ class Console: def __init__( self, *, - color_system: Optional[ - Literal["auto", "standard", "256", "truecolor", "windows"] - ] = "auto", + color_system: Optional[ConsoleColorSystem] = "auto", force_terminal: Optional[bool] = None, force_jupyter: Optional[bool] = None, force_interactive: Optional[bool] = None, @@ -880,11 +883,11 @@ class Console: return ThemeContext(self, theme, inherit) @property - def color_system(self) -> Optional[str]: + def color_system(self) -> Optional[ConsoleColorSystem]: """Get color system string. Returns: - Optional[str]: "standard", "256" or "truecolor". + Optional[ConsoleColorSystem]: "standard", "256", "truecolor" or "windows". """ if self._color_system is not None: