From b9ad6ba65dd6bdb3842bd8d884efd77b780badfb Mon Sep 17 00:00:00 2001 From: Nathan Page Date: Sun, 9 May 2021 15:56:04 -0700 Subject: [PATCH] remove try catch for type_extensions and replace with if sys.version_info --- examples/top_lite_simulator.py | 8 ++++---- rich/align.py | 12 ++++++------ rich/box.py | 7 ++++--- rich/live_render.py | 8 ++++---- 4 files changed, 18 insertions(+), 17 deletions(-) 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