From aa1858aa760ebd6f60c32ff94cc8e308d55eb733 Mon Sep 17 00:00:00 2001 From: Albin Saju Date: Wed, 18 Mar 2026 05:44:19 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=94=A7=20Update=20help=20text=20sanit?= =?UTF-8?q?ization=20to=20check=20for=20HAS=5FRICH=20before=20importing=20?= =?UTF-8?q?rich=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typer/_completion_classes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/typer/_completion_classes.py b/typer/_completion_classes.py index 8548fb4d6a..9845a73538 100644 --- a/typer/_completion_classes.py +++ b/typer/_completion_classes.py @@ -16,11 +16,12 @@ COMPLETION_SCRIPT_ZSH, Shells, ) +from .core import HAS_RICH def _sanitize_help_text(text: str) -> str: """Sanitizes the help text by removing rich tags""" - if not importlib.util.find_spec("rich"): + if not HAS_RICH or not importlib.util.find_spec("rich"): return text from . import rich_utils From 41cfbffb603f9aa8acc5fe42b56c9d1c18311233 Mon Sep 17 00:00:00 2001 From: Albin Saju Date: Wed, 18 Mar 2026 06:22:09 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=A7=AA=20Add=20test=20for=20help=20te?= =?UTF-8?q?xt=20sanitization=20when=20HAS=5FRICH=20is=20False?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_completion/test_sanitization.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_completion/test_sanitization.py b/tests/test_completion/test_sanitization.py index 9150b94cd5..37a4e2a28f 100644 --- a/tests/test_completion/test_sanitization.py +++ b/tests/test_completion/test_sanitization.py @@ -36,3 +36,10 @@ def test_sanitize_help_text( with patch("importlib.util.find_spec", return_value=find_spec) as mock_find_spec: assert _sanitize_help_text(help_text) == expected mock_find_spec.assert_called_once_with("rich") + + +def test_sanitize_help_text_no_rich(): + with patch("typer._completion_classes.HAS_RICH", False): + with patch("importlib.util.find_spec") as mock_find_spec: + assert _sanitize_help_text("help [bold]with[/] rich tags") == "help [bold]with[/] rich tags" + mock_find_spec.assert_not_called() From ab89b41446e3a2adcfd6ccdc2542502d0059e5c6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 18 Mar 2026 06:24:36 +0000 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_completion/test_sanitization.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_completion/test_sanitization.py b/tests/test_completion/test_sanitization.py index 37a4e2a28f..97e88b7c14 100644 --- a/tests/test_completion/test_sanitization.py +++ b/tests/test_completion/test_sanitization.py @@ -41,5 +41,8 @@ def test_sanitize_help_text( def test_sanitize_help_text_no_rich(): with patch("typer._completion_classes.HAS_RICH", False): with patch("importlib.util.find_spec") as mock_find_spec: - assert _sanitize_help_text("help [bold]with[/] rich tags") == "help [bold]with[/] rich tags" + assert ( + _sanitize_help_text("help [bold]with[/] rich tags") + == "help [bold]with[/] rich tags" + ) mock_find_spec.assert_not_called() From cb98d75989ddbf7a33cb485b5e3d3b17d72acb6a Mon Sep 17 00:00:00 2001 From: Albin Saju Date: Wed, 18 Mar 2026 06:24:36 +0000 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=A7=AA=20Remove=20unnecessary=20blank?= =?UTF-8?q?=20line=20in=20test=5Fsanitize=5Fhelp=5Ftext=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_completion/test_sanitization.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_completion/test_sanitization.py b/tests/test_completion/test_sanitization.py index 97e88b7c14..d231f94da3 100644 --- a/tests/test_completion/test_sanitization.py +++ b/tests/test_completion/test_sanitization.py @@ -37,7 +37,6 @@ def test_sanitize_help_text( assert _sanitize_help_text(help_text) == expected mock_find_spec.assert_called_once_with("rich") - def test_sanitize_help_text_no_rich(): with patch("typer._completion_classes.HAS_RICH", False): with patch("importlib.util.find_spec") as mock_find_spec: From 60c813332d784435495e98e06b80d284ca5f659a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 18 Mar 2026 06:25:51 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_completion/test_sanitization.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_completion/test_sanitization.py b/tests/test_completion/test_sanitization.py index d231f94da3..97e88b7c14 100644 --- a/tests/test_completion/test_sanitization.py +++ b/tests/test_completion/test_sanitization.py @@ -37,6 +37,7 @@ def test_sanitize_help_text( assert _sanitize_help_text(help_text) == expected mock_find_spec.assert_called_once_with("rich") + def test_sanitize_help_text_no_rich(): with patch("typer._completion_classes.HAS_RICH", False): with patch("importlib.util.find_spec") as mock_find_spec: