From 848fafe4923144097dedec12c3f6af03ffd3c206 Mon Sep 17 00:00:00 2001 From: Kadir Can Ozden <101993364+bysiber@users.noreply.github.com> Date: Fri, 20 Feb 2026 11:47:02 +0300 Subject: [PATCH 1/4] Fix Option(None) in Annotated crashing with AttributeError When using Annotated[str, Option(None)], the None default gets reinterpreted as a param_decl name since 'None is not ...' is True. Click then crashes calling .isidentifier() on None. Added an isinstance(str) check so only actual strings are treated as param_decl names. Non-string defaults are left as-is. --- typer/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/typer/utils.py b/typer/utils.py index addf9334d4..9088234c7b 100644 --- a/typer/utils.py +++ b/typer/utils.py @@ -141,6 +141,7 @@ def get_params_from_function(func: Callable[..., Any]) -> dict[str, ParamMeta]: if ( isinstance(parameter_info, OptionInfo) and parameter_info.default is not ... + and isinstance(parameter_info.default, str) ): parameter_info.param_decls = ( cast(str, parameter_info.default), From 4f15543428460ce21f42476c1e26037c7f477f32 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Mon, 16 Mar 2026 13:29:42 +0100 Subject: [PATCH 2/4] remove redundant cast --- typer/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typer/utils.py b/typer/utils.py index 9088234c7b..e1c8321c8b 100644 --- a/typer/utils.py +++ b/typer/utils.py @@ -144,7 +144,7 @@ def get_params_from_function(func: Callable[..., Any]) -> dict[str, ParamMeta]: and isinstance(parameter_info.default, str) ): parameter_info.param_decls = ( - cast(str, parameter_info.default), + str, parameter_info.default, *(parameter_info.param_decls or ()), ) parameter_info.default = ... From 3ee1cfcff77aaaba5d8bda44e8b411f0463a6b05 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 16 Mar 2026 12:30:16 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typer/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/typer/utils.py b/typer/utils.py index e1c8321c8b..6c114e902d 100644 --- a/typer/utils.py +++ b/typer/utils.py @@ -1,7 +1,7 @@ import inspect from collections.abc import Callable from copy import copy -from typing import Any, cast +from typing import Any from ._typing import Annotated, get_args, get_origin, get_type_hints from .models import ArgumentInfo, OptionInfo, ParameterInfo, ParamMeta @@ -144,7 +144,8 @@ def get_params_from_function(func: Callable[..., Any]) -> dict[str, ParamMeta]: and isinstance(parameter_info.default, str) ): parameter_info.param_decls = ( - str, parameter_info.default, + str, + parameter_info.default, *(parameter_info.param_decls or ()), ) parameter_info.default = ... From dae4f37f229da087f819edcc0a45938926525136 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 16 Mar 2026 13:37:07 +0100 Subject: [PATCH 4/4] fix --- typer/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/typer/utils.py b/typer/utils.py index 6c114e902d..3bf0be9c1e 100644 --- a/typer/utils.py +++ b/typer/utils.py @@ -144,7 +144,6 @@ def get_params_from_function(func: Callable[..., Any]) -> dict[str, ParamMeta]: and isinstance(parameter_info.default, str) ): parameter_info.param_decls = ( - str, parameter_info.default, *(parameter_info.param_decls or ()), )