Skip to content

Remove runtime dependency on typing-extensions #3700

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

- The dependency on `typing_extensions` has been removed

## [14.0.0] - 2025-03-30

### Added
Expand Down
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 = { version = ">=4.0.0, <5.0", python = "<3.11" }

[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 List, Optional, Protocol, Sequence, cast


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, Literal, Optional

from .constrain import Constrain
from .jupyter import JupyterMixin
Expand Down
9 changes: 1 addition & 8 deletions rich/box.py
Original file line number Diff line number Diff line change
@@ -1,11 +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
12 changes: 3 additions & 9 deletions rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,21 @@
Dict,
Iterable,
List,
Literal,
Mapping,
NamedTuple,
Optional,
Protocol,
TextIO,
Tuple,
Type,
Union,
cast,
runtime_checkable,
)

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 . import errors, themes
from ._emoji_replace import _emoji_replace
from ._export_format import CONSOLE_HTML_FORMAT, CONSOLE_SVG_FORMAT
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, Final, Iterable, List, Union

from .segment import ControlCode, ControlType, Segment

Expand Down
13 changes: 3 additions & 10 deletions rich/emoji.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import sys
from typing import TYPE_CHECKING, Optional, Union
from typing import TYPE_CHECKING, Literal, Optional, Union

from ._emoji_codes import EMOJI
from ._emoji_replace import _emoji_replace
Comment on lines +3 to +4
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra changes here are from the isort pre-commit hook. I ran isort, throwing out any changes on files that I didn't modify manually. If desired, I can revert these extra changes too, but presumably the codebase is meant to be isort-compliant?

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
9 changes: 1 addition & 8 deletions rich/live_render.py
Original file line number Diff line number Diff line change
@@ -1,11 +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 Literal, Optional, Tuple

from ._loop import loop_last
from .console import Console, ConsoleOptions, RenderableType, RenderResult
Expand Down
8 changes: 1 addition & 7 deletions rich/markdown.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
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
18 changes: 8 additions & 10 deletions rich/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from threading import Event, RLock, Thread
from types import TracebackType
from typing import (
TYPE_CHECKING,
Any,
BinaryIO,
Callable,
Expand All @@ -23,6 +24,7 @@
Generic,
Iterable,
List,
Literal,
NamedTuple,
NewType,
Optional,
Expand All @@ -34,15 +36,11 @@
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:
from typing_extensions import Self # pragma: no cover
if TYPE_CHECKING:
if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self # pragma: no cover

from . import filesize, get_console
from .console import Console, Group, JustifyMethod, RenderableType
Expand Down Expand Up @@ -1178,7 +1176,7 @@ def stop(self) -> None:
if not self.console.is_interactive and not self.console.is_jupyter:
self.console.print()

def __enter__(self) -> Self:
def __enter__(self) -> "Self":
self.start()
return self

Expand Down