From fb4217acb122616123f7b225cfa38b03b3efce88 Mon Sep 17 00:00:00 2001 From: Nathan Page Date: Sun, 9 May 2021 14:58:24 -0700 Subject: [PATCH] add in splitting of regex callable func --- rich/__main__.py | 3 ++- rich/_emoji_replace.py | 6 ++++-- rich/markup.py | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/rich/__main__.py b/rich/__main__.py index affbe6bd..59fbd256 100644 --- a/rich/__main__.py +++ b/rich/__main__.py @@ -11,6 +11,7 @@ from rich.console import ( ConsoleRenderable, RenderGroup, RenderResult, + RenderableType, ) from rich.markdown import Markdown from rich.measure import Measurement @@ -95,7 +96,7 @@ def make_test_card() -> Table: ), ) - def comparison(renderable1: Any, renderable2: Any) -> Table: + def comparison(renderable1: RenderableType, renderable2: RenderableType) -> Table: table = Table(show_header=False, pad_edge=False, box=None, expand=True) table.add_column("1", ratio=1) table.add_column("2", ratio=1) diff --git a/rich/_emoji_replace.py b/rich/_emoji_replace.py index 88122187..8539fd67 100644 --- a/rich/_emoji_replace.py +++ b/rich/_emoji_replace.py @@ -5,11 +5,13 @@ import re from ._emoji_codes import EMOJI -_EmojiSub = Callable[[Callable[[Match[str]], str], str], str] +_ReStringMatch = Match[str] # regex match object +_ReSubCallable = Callable[[_ReStringMatch], str] # Callable invoked by re.sub +_EmojiSubMethod = Callable[[_ReSubCallable, str], str] # Sub method of a compiled re def _emoji_replace( - text: str, _emoji_sub: _EmojiSub = re.compile(r"(:(\S*?):)").sub + text: str, _emoji_sub: _EmojiSubMethod = re.compile(r"(:(\S*?):)").sub ) -> str: """Replace emoji code in text.""" get_emoji = EMOJI.get diff --git a/rich/markup.py b/rich/markup.py index d208e7cd..179cabc5 100644 --- a/rich/markup.py +++ b/rich/markup.py @@ -36,11 +36,13 @@ class Tag(NamedTuple): ) -_EscapeSub = Callable[[Callable[[Match[str]], str], str], str] +_ReStringMatch = Match[str] # regex match object +_ReSubCallable = Callable[[_ReStringMatch], str] # Callable invoked by re.sub +_EscapeSubMethod = Callable[[_ReSubCallable, str], str] # Sub method of a compiled re def escape( - markup: str, _escape: _EscapeSub = re.compile(r"(\\*)(\[[a-z#\/].*?\])").sub + markup: str, _escape: _EscapeSubMethod = re.compile(r"(\\*)(\[[a-z#\/].*?\])").sub ) -> str: """Escapes text so that it won't be interpreted as markup.