diff --git a/examples/top_lite_simulator.py b/examples/top_lite_simulator.py index 626564dc..4fecaaa8 100644 --- a/examples/top_lite_simulator.py +++ b/examples/top_lite_simulator.py @@ -1,7 +1,7 @@ """Lite simulation of the top linux command.""" - import datetime import random +import sys import time from dataclasses import dataclass @@ -10,10 +10,10 @@ from rich.console import Console from rich.live import Live from rich.table import Table -try: - from typing_extensions import Literal -except ImportError: +if sys.version_info >= (3, 8): from typing import Literal +else: + from typing_extensions import Literal @dataclass diff --git a/rich/align.py b/rich/align.py index c34d58f5..22e4c60f 100644 --- a/rich/align.py +++ b/rich/align.py @@ -1,10 +1,11 @@ +import sys from itertools import chain -from typing import Iterable, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Iterable, Optional -try: +if sys.version_info >= (3, 8): + from typing import Literal +else: from typing_extensions import Literal -except ImportError: # pragma: no cover - from typing import Literal # type: ignore from .constrain import Constrain from .jupyter import JupyterMixin @@ -12,9 +13,8 @@ from .measure import Measurement from .segment import Segment from .style import StyleType - if TYPE_CHECKING: - from .console import Console, ConsoleOptions, RenderResult, RenderableType + from .console import Console, ConsoleOptions, RenderableType, RenderResult AlignMethod = Literal["left", "center", "right"] VerticalAlignMethod = Literal["top", "middle", "bottom"] diff --git a/rich/box.py b/rich/box.py index d2951695..d044f74a 100644 --- a/rich/box.py +++ b/rich/box.py @@ -1,9 +1,10 @@ +import sys from typing import TYPE_CHECKING, Iterable, List -try: +if sys.version_info >= (3, 8): + from typing import Literal +else: from typing_extensions import Literal -except ImportError: # pragma: no cover - from typing import Literal # type: ignore from ._loop import loop_last diff --git a/rich/live_render.py b/rich/live_render.py index 6d0f7b82..63b6c5cf 100644 --- a/rich/live_render.py +++ b/rich/live_render.py @@ -1,10 +1,10 @@ -from threading import RLock +import sys from typing import Optional, Tuple -try: +if sys.version_info >= (3, 8): + from typing import Literal +else: from typing_extensions import Literal -except ImportError: # pragma: no cover - from typing import Literal # type: ignore from ._loop import loop_last