diff --git a/CHANGELOG.md b/CHANGELOG.md index 667d105011..cb14769560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## [Unreleased] ### Changed +- Removed `typing_extensions` from runtime dependencies https://github.com/Textualize/rich/pull/3763 - Live objects (including Progress) may now be nested https://github.com/Textualize/rich/pull/3768 ## [14.0.0] - 2025-03-30 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9893915a4a..10268ddc9b 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -67,6 +67,7 @@ The following people have contributed to the development of Rich: - [Louis Sautier](https://github.com/sbraz) - [Tim Savage](https://github.com/timsavage) - [Anthony Shaw](https://github.com/tonybaloney) +- [Damian Shaw](https://github.com/notatallshaw) - [Nicolas Simonds](https://github.com/0xDEC0DE) - [Aaron Stephens](https://github.com/aaronst) - [Karolina Surma](https://github.com/befeleme) diff --git a/docs/source/conf.py b/docs/source/conf.py index 6f82deda28..cf89231413 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -17,14 +17,8 @@ # -- Project information ----------------------------------------------------- -import sys - import sphinx_rtd_theme - -if sys.version_info >= (3, 8): - from importlib.metadata import Distribution -else: - from importlib_metadata import Distribution +from importlib.metadata import Distribution html_theme = "sphinx_rtd_theme" diff --git a/examples/top_lite_simulator.py b/examples/top_lite_simulator.py index 147cbb0f96..f3eec0d19a 100644 --- a/examples/top_lite_simulator.py +++ b/examples/top_lite_simulator.py @@ -1,7 +1,6 @@ """Lite simulation of the top linux command.""" import datetime import random -import sys import time from dataclasses import dataclass @@ -9,11 +8,7 @@ from rich.console import Console from rich.live import Live from rich.table import Table - -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal +from typing import Literal @dataclass diff --git a/poetry.lock b/poetry.lock index 689b7aefbf..7cd4cb2907 100644 --- a/poetry.lock +++ b/poetry.lock @@ -971,4 +971,4 @@ jupyter = ["ipywidgets"] [metadata] lock-version = "2.0" python-versions = ">=3.8.0" -content-hash = "88737d425a4f8d5b3b82a50e3895bbad0088a8868f7637f425a429a2e2299c45" +content-hash = "2e87c73a127b5e6456de92c6cab8e8be8f746f2c4d792ae0563ae74e19593e4c" diff --git a/pyproject.toml b/pyproject.toml index 41ccb1fafb..65c9623b90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,6 @@ include = ["rich/py.typed"] [tool.poetry.dependencies] python = ">=3.8.0" -typing-extensions = { version = ">=4.0.0, <5.0", python = "<3.11" } pygments = "^2.13.0" ipywidgets = { version = ">=7.5.1,<9", optional = true } markdown-it-py = ">=2.2.0" @@ -44,6 +43,7 @@ pytest-cov = "^3.0.0" attrs = "^21.4.0" pre-commit = "^2.17.0" asv = "^0.5.1" +typing-extensions = ">=4.0.0, <5.0" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/rich/_ratio.py b/rich/_ratio.py index e12397af6f..5fd5a383d2 100644 --- a/rich/_ratio.py +++ b/rich/_ratio.py @@ -1,12 +1,6 @@ -import sys from fractions import Fraction from math import ceil -from typing import cast, List, Optional, Sequence - -if sys.version_info >= (3, 8): - from typing import Protocol -else: - from typing_extensions import Protocol # pragma: no cover +from typing import cast, List, Optional, Sequence, Protocol class Edge(Protocol): diff --git a/rich/align.py b/rich/align.py index fac50b1e36..cb5f31d639 100644 --- a/rich/align.py +++ b/rich/align.py @@ -1,11 +1,5 @@ -import sys from itertools import chain -from typing import TYPE_CHECKING, Iterable, Optional - -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal # pragma: no cover +from typing import TYPE_CHECKING, Iterable, Optional, Literal from .constrain import Constrain from .jupyter import JupyterMixin diff --git a/rich/box.py b/rich/box.py index aa4ada32ed..82555b61cd 100644 --- a/rich/box.py +++ b/rich/box.py @@ -1,10 +1,4 @@ -import sys -from typing import TYPE_CHECKING, Iterable, List - -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal # pragma: no cover +from typing import TYPE_CHECKING, Iterable, List, Literal from ._loop import loop_last diff --git a/rich/console.py b/rich/console.py index 6d335b3068..5929fb1c56 100644 --- a/rich/console.py +++ b/rich/console.py @@ -33,15 +33,7 @@ ) from rich._null_file import NULL_FILE - -if sys.version_info >= (3, 8): - from typing import Literal, Protocol, runtime_checkable -else: - from typing_extensions import ( - Literal, - Protocol, - runtime_checkable, - ) # pragma: no cover +from typing import Literal, Protocol, runtime_checkable from . import errors, themes from ._emoji_replace import _emoji_replace diff --git a/rich/control.py b/rich/control.py index a8a912553a..248b0f595a 100644 --- a/rich/control.py +++ b/rich/control.py @@ -1,11 +1,5 @@ -import sys import time -from typing import TYPE_CHECKING, Callable, Dict, Iterable, List, Union - -if sys.version_info >= (3, 8): - from typing import Final -else: - from typing_extensions import Final # pragma: no cover +from typing import TYPE_CHECKING, Callable, Dict, Iterable, List, Union, Final from .segment import ControlCode, ControlType, Segment diff --git a/rich/emoji.py b/rich/emoji.py index d5a1062a96..9433e6fb3f 100644 --- a/rich/emoji.py +++ b/rich/emoji.py @@ -1,5 +1,5 @@ import sys -from typing import TYPE_CHECKING, Optional, Union +from typing import TYPE_CHECKING, Optional, Union, Literal from .jupyter import JupyterMixin from .segment import Segment @@ -7,11 +7,6 @@ from ._emoji_codes import EMOJI from ._emoji_replace import _emoji_replace -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal # pragma: no cover - if TYPE_CHECKING: from .console import Console, ConsoleOptions, RenderResult diff --git a/rich/live_render.py b/rich/live_render.py index 4284cccc4b..d3da5111d8 100644 --- a/rich/live_render.py +++ b/rich/live_render.py @@ -1,10 +1,4 @@ -import sys -from typing import Optional, Tuple - -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal # pragma: no cover +from typing import Optional, Tuple, Literal from ._loop import loop_last diff --git a/rich/markdown.py b/rich/markdown.py index 26c58d1558..12496487b2 100644 --- a/rich/markdown.py +++ b/rich/markdown.py @@ -1,16 +1,11 @@ from __future__ import annotations import sys -from typing import ClassVar, Iterable +from typing import ClassVar, Iterable, get_args from markdown_it import MarkdownIt from markdown_it.token import Token -if sys.version_info >= (3, 8): - from typing import get_args -else: - from typing_extensions import get_args # pragma: no cover - from rich.table import Table from . import box diff --git a/rich/progress.py b/rich/progress.py index 1e92eb6b13..a529b24496 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -1,5 +1,6 @@ +from __future__ import annotations + import io -import sys import typing import warnings from abc import ABC, abstractmethod @@ -14,6 +15,7 @@ from threading import Event, RLock, Thread from types import TracebackType from typing import ( + TYPE_CHECKING, Any, BinaryIO, Callable, @@ -23,6 +25,7 @@ Generic, Iterable, List, + Literal, NamedTuple, NewType, Optional, @@ -34,14 +37,8 @@ Union, ) -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal # pragma: no cover - -if sys.version_info >= (3, 11): - from typing import Self -else: +if TYPE_CHECKING: + # Can be replaced with `from typing import Self` in Python 3.11+ from typing_extensions import Self # pragma: no cover from . import filesize, get_console diff --git a/tests/test_syntax.py b/tests/test_syntax.py index 64288b3faa..04edb9cc3e 100644 --- a/tests/test_syntax.py +++ b/tests/test_syntax.py @@ -19,11 +19,7 @@ ) from .render import render - -if sys.version_info >= (3, 8): - from importlib.metadata import Distribution -else: - from importlib_metadata import Distribution +from importlib.metadata import Distribution PYGMENTS_VERSION = Distribution.from_name("pygments").version OLD_PYGMENTS = PYGMENTS_VERSION == "2.13.0"