From 81b12554b3b15374aa48dae3f6507202bd8fab3e Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 24 Jun 2025 13:34:17 +0100 Subject: [PATCH] Self typing --- rich/live.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rich/live.py b/rich/live.py index 85faca8068..cc3a39bd57 100644 --- a/rich/live.py +++ b/rich/live.py @@ -1,7 +1,9 @@ +from __future__ import annotations + import sys from threading import Event, RLock, Thread from types import TracebackType -from typing import IO, Any, Callable, List, Optional, TextIO, Type, cast +from typing import IO, TYPE_CHECKING, Any, Callable, List, Optional, TextIO, Type, cast from . import get_console from .console import Console, ConsoleRenderable, Group, RenderableType, RenderHook @@ -12,6 +14,10 @@ from .screen import Screen from .text import Text +if TYPE_CHECKING: + # Can be replaced with `from typing import Self` in Python 3.11+ + from typing_extensions import Self # pragma: no cover + class _RefreshThread(Thread): """A thread that calls refresh() at regular intervals.""" @@ -170,7 +176,7 @@ def stop(self) -> None: if self.ipy_widget is not None and self.transient: self.ipy_widget.close() # pragma: no cover - def __enter__(self) -> "Live": + def __enter__(self) -> Self: self.start(refresh=self._renderable is not None) return self