From 27fe68c85fda8d78c2ff47e751dd2a37a8be6f65 Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Sun, 15 Jun 2025 11:02:57 -0400 Subject: [PATCH 1/6] Remove all `sys.version_info >= (3, 8)` checks as Python 3.7 is no longer supported --- docs/source/conf.py | 8 +------- examples/top_lite_simulator.py | 7 +------ rich/_ratio.py | 8 +------- rich/align.py | 8 +------- rich/box.py | 8 +------- rich/console.py | 10 +--------- rich/control.py | 8 +------- rich/emoji.py | 7 +------ rich/live_render.py | 8 +------- rich/markdown.py | 7 +------ rich/progress.py | 6 +----- tests/test_syntax.py | 6 +----- 12 files changed, 12 insertions(+), 79 deletions(-) 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/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 6725e405c3..bfedfa8490 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..c7070a619d 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -33,11 +33,7 @@ TypeVar, Union, ) - -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal # pragma: no cover +from typing import Literal if sys.version_info >= (3, 11): from typing import Self diff --git a/tests/test_syntax.py b/tests/test_syntax.py index bbd4c7a5cb..c42ad73186 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" From 90d1265914fdcea4e9a15ddbac5c1a82f6793cfa Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Sun, 15 Jun 2025 11:19:56 -0400 Subject: [PATCH 2/6] Move `typing_extensions` into `TYPE_CHECKING` block --- rich/progress.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rich/progress.py b/rich/progress.py index c7070a619d..fbfe19ba97 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, @@ -35,10 +37,9 @@ ) from typing import Literal -if sys.version_info >= (3, 11): - from typing import Self -else: - from typing_extensions import Self # pragma: no cover +if TYPE_CHECKING: + # Can be replaced with `from typing import Self` in Python 3.11+ + from typing_extensions import Self from . import filesize, get_console from .console import Console, Group, JustifyMethod, RenderableType From 7c49720c3b17e4f03734811609ec5327b7d482b5 Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Sun, 15 Jun 2025 11:21:36 -0400 Subject: [PATCH 3/6] Update `typing-extensions` to be a dev only dependency --- poetry.lock | 2 +- pyproject.toml | 2 +- rich/progress.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/poetry.lock b/poetry.lock index a089eccf68..945d6b332f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -929,4 +929,4 @@ jupyter = ["ipywidgets"] [metadata] lock-version = "2.0" python-versions = ">=3.8.0" -content-hash = "804a37e7036779a41ab3dfe0cab6324de5095f81684e7db724ba803b26159b60" +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/progress.py b/rich/progress.py index fbfe19ba97..b9eaecf2df 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -25,6 +25,7 @@ Generic, Iterable, List, + Literal, NamedTuple, NewType, Optional, @@ -35,7 +36,6 @@ TypeVar, Union, ) -from typing import Literal if TYPE_CHECKING: # Can be replaced with `from typing import Self` in Python 3.11+ From 3f5425e074b4db472156b183ece2840363759ccc Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Sun, 15 Jun 2025 11:25:52 -0400 Subject: [PATCH 4/6] Add to changelog and contributors --- CHANGELOG.md | 6 ++++++ CONTRIBUTORS.md | 1 + 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10933867af..4d23897ccc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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] + +### Changed + +- Moved `typing_extensions` from runtime dependencies to dev dependencies + ## [14.0.0] - 2025-03-30 ### Added 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) From 1dc0d58ac61e97d969a6a7dae275016c067bc25a Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Sun, 15 Jun 2025 14:31:26 -0400 Subject: [PATCH 5/6] Add back `# pragma: no cover` --- rich/progress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rich/progress.py b/rich/progress.py index b9eaecf2df..a529b24496 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -39,7 +39,7 @@ if TYPE_CHECKING: # Can be replaced with `from typing import Self` in Python 3.11+ - from typing_extensions import Self + from typing_extensions import Self # pragma: no cover from . import filesize, get_console from .console import Console, Group, JustifyMethod, RenderableType From 3423cb28827b6b40cafaaffb62c95d7fdffe3fef Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Sun, 15 Jun 2025 14:33:17 -0400 Subject: [PATCH 6/6] Add PR link and update changelog description --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d23897ccc..9cc62aeb5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Moved `typing_extensions` from runtime dependencies to dev dependencies +- Removed `typing_extensions` from runtime dependencies https://github.com/Textualize/rich/pull/3763 ## [14.0.0] - 2025-03-30