Skip to content

Remove typing-extensions as a runtime dependency #3763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 1 addition & 6 deletions examples/top_lite_simulator.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
"""Lite simulation of the top linux command."""
import datetime
import random
import sys
import time
from dataclasses import dataclass

from rich import box
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
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
Expand Down
8 changes: 1 addition & 7 deletions rich/_ratio.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
8 changes: 1 addition & 7 deletions rich/align.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 1 addition & 7 deletions rich/box.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 1 addition & 9 deletions rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions rich/control.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
7 changes: 1 addition & 6 deletions rich/emoji.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
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
from .style import Style
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
Expand Down
8 changes: 1 addition & 7 deletions rich/live_render.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions rich/markdown.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 6 additions & 9 deletions rich/progress.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import io
import sys
import typing
import warnings
from abc import ABC, abstractmethod
Expand All @@ -14,6 +15,7 @@
from threading import Event, RLock, Thread
from types import TracebackType
from typing import (
TYPE_CHECKING,
Any,
BinaryIO,
Callable,
Expand All @@ -23,6 +25,7 @@
Generic,
Iterable,
List,
Literal,
NamedTuple,
NewType,
Optional,
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions tests/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down