diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3289dd0950..4ea5b873a6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.0 + rev: v0.6.1 hooks: - id: ruff args: diff --git a/requirements-tests.txt b/requirements-tests.txt index ac6377c10d..0cacd0ecbe 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -6,7 +6,7 @@ coverage[toml] >=6.2,<8.0 pytest-xdist >=1.32.0,<4.0.0 pytest-sugar >=0.9.4,<1.1.0 mypy ==1.4.1 -ruff ==0.2.0 +ruff ==0.6.1 # Needed explicitly by typer-slim rich >=10.11.0 shellingham >=1.3.0 diff --git a/tests/test_ambiguous_params.py b/tests/test_ambiguous_params.py index 4dbf09b569..0693c8e9aa 100644 --- a/tests/test_ambiguous_params.py +++ b/tests/test_ambiguous_params.py @@ -29,8 +29,7 @@ def test_forbid_default_value_in_annotated_argument(): # This test case only works with `typer.Argument`. `typer.Option` uses positionals # for param_decls too. @app.command() - def cmd(my_param: Annotated[str, typer.Argument("foo")]): - ... # pragma: no cover + def cmd(my_param: Annotated[str, typer.Argument("foo")]): ... # pragma: no cover with pytest.raises(AnnotatedParamWithDefaultValueError) as excinfo: runner.invoke(app) @@ -64,8 +63,7 @@ def test_forbid_annotated_param_and_default_param(param, param_info_type): app = typer.Typer() @app.command() - def cmd(my_param: Annotated[str, param()] = param("foo")): - ... # pragma: no cover + def cmd(my_param: Annotated[str, param()] = param("foo")): ... # pragma: no cover with pytest.raises(MixedAnnotatedAndDefaultStyleError) as excinfo: runner.invoke(app) @@ -83,8 +81,7 @@ def test_forbid_multiple_typer_params_in_annotated(): @app.command() def cmd( my_param: Annotated[str, typer.Argument(), typer.Argument()], - ): - ... # pragma: no cover + ): ... # pragma: no cover with pytest.raises(MultipleTyperAnnotationsError) as excinfo: runner.invoke(app) @@ -121,8 +118,7 @@ def make_string(): @app.command() def cmd( my_param: Annotated[str, param(default_factory=make_string)] = "hello", - ): - ... # pragma: no cover + ): ... # pragma: no cover with pytest.raises(DefaultFactoryAndDefaultValueError) as excinfo: runner.invoke(app) @@ -171,8 +167,7 @@ def make_string(): @app.command() def cmd( my_param: str = param("hi", default_factory=make_string), - ): - ... # pragma: no cover + ): ... # pragma: no cover with pytest.raises(DefaultFactoryAndDefaultValueError) as excinfo: runner.invoke(app) diff --git a/typer/main.py b/typer/main.py index 013939bf20..c385c48c5f 100644 --- a/typer/main.py +++ b/typer/main.py @@ -715,9 +715,9 @@ def get_click_type( elif parameter_info.parser is not None: return click.types.FuncParamType(parameter_info.parser) - elif annotation == str: + elif annotation is str: return click.STRING - elif annotation == int: + elif annotation is int: if parameter_info.min is not None or parameter_info.max is not None: min_ = None max_ = None @@ -728,7 +728,7 @@ def get_click_type( return click.IntRange(min=min_, max=max_, clamp=parameter_info.clamp) else: return click.INT - elif annotation == float: + elif annotation is float: if parameter_info.min is not None or parameter_info.max is not None: return click.FloatRange( min=parameter_info.min, @@ -737,7 +737,7 @@ def get_click_type( ) else: return click.FLOAT - elif annotation == bool: + elif annotation is bool: return click.BOOL elif annotation == UUID: return click.UUID diff --git a/typer/params.py b/typer/params.py index 710a4cf136..2fd025c90d 100644 --- a/typer/params.py +++ b/typer/params.py @@ -68,8 +68,7 @@ def Option( path_type: Union[None, Type[str], Type[bytes]] = None, # Rich settings rich_help_panel: Union[str, None] = None, -) -> Any: - ... +) -> Any: ... # Overload for Option created with custom type 'click_type' @@ -132,8 +131,7 @@ def Option( path_type: Union[None, Type[str], Type[bytes]] = None, # Rich settings rich_help_panel: Union[str, None] = None, -) -> Any: - ... +) -> Any: ... def Option( @@ -305,8 +303,7 @@ def Argument( path_type: Union[None, Type[str], Type[bytes]] = None, # Rich settings rich_help_panel: Union[str, None] = None, -) -> Any: - ... +) -> Any: ... # Overload for Argument created with custom type 'click_type' @@ -361,8 +358,7 @@ def Argument( path_type: Union[None, Type[str], Type[bytes]] = None, # Rich settings rich_help_panel: Union[str, None] = None, -) -> Any: - ... +) -> Any: ... def Argument( diff --git a/typer/rich_utils.py b/typer/rich_utils.py index cf0538e914..900f4b4e87 100644 --- a/typer/rich_utils.py +++ b/typer/rich_utils.py @@ -68,9 +68,9 @@ STYLE_ABORTED = "red" _TERMINAL_WIDTH = getenv("TERMINAL_WIDTH") MAX_WIDTH = int(_TERMINAL_WIDTH) if _TERMINAL_WIDTH else None -COLOR_SYSTEM: Optional[ - Literal["auto", "standard", "256", "truecolor", "windows"] -] = "auto" # Set to None to disable colors +COLOR_SYSTEM: Optional[Literal["auto", "standard", "256", "truecolor", "windows"]] = ( + "auto" # Set to None to disable colors +) _TYPER_FORCE_DISABLE_TERMINAL = getenv("_TYPER_FORCE_DISABLE_TERMINAL") FORCE_TERMINAL = ( True