From 9485f41b6ddb1c9cef74b992e7fc850ea4fd08c2 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Mon, 15 Sep 2025 13:57:20 +0800 Subject: [PATCH 1/6] refactor: no typing_extensions for python 3.10+ --- pyproject.toml | 2 +- requirements-tests.txt | 4 ++-- tests/assets/cli/rich_formatted_app.py | 2 +- tests/test_ambiguous_params.py | 4 ++-- tests/test_annotated.py | 2 +- tests/test_future_annotations.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c0ca3aa418..48c541e4fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ classifiers = [ ] dependencies = [ "click >= 8.0.0", - "typing-extensions >= 3.7.4.3", + "typing-extensions >= 3.7.4.3; python_version < '3.10'", ] readme = "README.md" [project.urls] diff --git a/requirements-tests.txt b/requirements-tests.txt index 81b84e4b32..ca4aa99d80 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -5,8 +5,8 @@ pytest-cov >=2.10.0,<8.0.0 coverage[toml] >=6.2,<8.0 pytest-xdist >=1.32.0,<4.0.0 pytest-sugar >=0.9.4,<1.2.0 -mypy ==1.4.1 -ruff ==0.12.12 +mypy ==1.18.1 +ruff ==0.13.0 # Needed explicitly by typer-slim rich >=10.11.0 shellingham >=1.3.0 diff --git a/tests/assets/cli/rich_formatted_app.py b/tests/assets/cli/rich_formatted_app.py index 54d8a52267..b6a01cd5c8 100644 --- a/tests/assets/cli/rich_formatted_app.py +++ b/tests/assets/cli/rich_formatted_app.py @@ -1,5 +1,5 @@ import typer -from typing_extensions import Annotated +from typer._typing import Annotated app = typer.Typer(rich_markup_mode="rich") diff --git a/tests/test_ambiguous_params.py b/tests/test_ambiguous_params.py index 0693c8e9aa..3fd1caceb2 100644 --- a/tests/test_ambiguous_params.py +++ b/tests/test_ambiguous_params.py @@ -1,5 +1,6 @@ import pytest import typer +from typer._typing import Annotated from typer.testing import CliRunner from typer.utils import ( AnnotatedParamWithDefaultValueError, @@ -8,7 +9,6 @@ MultipleTyperAnnotationsError, _split_annotation_from_typer_annotations, ) -from typing_extensions import Annotated runner = CliRunner() @@ -93,7 +93,7 @@ def test_allow_multiple_non_typer_params_in_annotated(): app = typer.Typer() @app.command() - def cmd(my_param: Annotated[str, "someval", typer.Argument(), 4] = "hello"): + def cmd(my_param: Annotated[str, "someval", typer.Argument(), 4] = "hello"): # noqa:F821 print(my_param) result = runner.invoke(app) diff --git a/tests/test_annotated.py b/tests/test_annotated.py index c1be5b88d7..f6f35c5b44 100644 --- a/tests/test_annotated.py +++ b/tests/test_annotated.py @@ -2,8 +2,8 @@ from pathlib import Path import typer +from typer._typing import Annotated from typer.testing import CliRunner -from typing_extensions import Annotated from .utils import needs_py310 diff --git a/tests/test_future_annotations.py b/tests/test_future_annotations.py index e820cd0923..443415636a 100644 --- a/tests/test_future_annotations.py +++ b/tests/test_future_annotations.py @@ -1,8 +1,8 @@ from __future__ import annotations import typer +from typer._typing import Annotated from typer.testing import CliRunner -from typing_extensions import Annotated runner = CliRunner() From 79ab53be7e267573d5200ea7547831c042df34d7 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Tue, 16 Sep 2025 10:37:24 +0200 Subject: [PATCH 2/6] Revert bumping mypy and ruff --- requirements-tests.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index ca4aa99d80..81b84e4b32 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -5,8 +5,8 @@ pytest-cov >=2.10.0,<8.0.0 coverage[toml] >=6.2,<8.0 pytest-xdist >=1.32.0,<4.0.0 pytest-sugar >=0.9.4,<1.2.0 -mypy ==1.18.1 -ruff ==0.13.0 +mypy ==1.4.1 +ruff ==0.12.12 # Needed explicitly by typer-slim rich >=10.11.0 shellingham >=1.3.0 From 53ca5dd3a21331e4532d9b4b8a63bec1d316fc92 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Wed, 17 Sep 2025 21:09:21 +0800 Subject: [PATCH 3/6] Only install `typing_extensions` for python <3.9 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 48c541e4fc..e28598dea7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ classifiers = [ ] dependencies = [ "click >= 8.0.0", - "typing-extensions >= 3.7.4.3; python_version < '3.10'", + "typing-extensions >= 3.7.4.3; python_version < '3.9'", ] readme = "README.md" [project.urls] From d464f1b8ed348fc1225818ce121a04e99faa8436 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Wed, 17 Sep 2025 21:13:29 +0800 Subject: [PATCH 4/6] refactor: import Literal from `typer._typing` --- typer/rich_utils.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/typer/rich_utils.py b/typer/rich_utils.py index d4c3676aea..eda57575e6 100644 --- a/typer/rich_utils.py +++ b/typer/rich_utils.py @@ -23,13 +23,9 @@ from rich.text import Text from rich.theme import Theme from rich.traceback import Traceback +from typer._typing import Literal from typer.models import DeveloperExceptionConfig -if sys.version_info >= (3, 9): - from typing import Literal -else: - from typing_extensions import Literal - # Default styles STYLE_OPTION = "bold cyan" STYLE_SWITCH = "bold green" From df102c9c277a0966b00320ef427593b28b9b782d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 17 Sep 2025 13:13:45 +0000 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typer/rich_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/typer/rich_utils.py b/typer/rich_utils.py index eda57575e6..48d9e2e920 100644 --- a/typer/rich_utils.py +++ b/typer/rich_utils.py @@ -2,7 +2,6 @@ import inspect import io -import sys from collections import defaultdict from gettext import gettext as _ from os import getenv From 6b0c4d6dddd5c60327e5387358042885fd723af7 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Wed, 17 Sep 2025 22:26:42 +0800 Subject: [PATCH 6/6] Rollback rich utils --- typer/rich_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/typer/rich_utils.py b/typer/rich_utils.py index 48d9e2e920..d4c3676aea 100644 --- a/typer/rich_utils.py +++ b/typer/rich_utils.py @@ -2,6 +2,7 @@ import inspect import io +import sys from collections import defaultdict from gettext import gettext as _ from os import getenv @@ -22,9 +23,13 @@ from rich.text import Text from rich.theme import Theme from rich.traceback import Traceback -from typer._typing import Literal from typer.models import DeveloperExceptionConfig +if sys.version_info >= (3, 9): + from typing import Literal +else: + from typing_extensions import Literal + # Default styles STYLE_OPTION = "bold cyan" STYLE_SWITCH = "bold green"