From e2135d58265dd00c88947b4681e76b01dc94a114 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Jul 2023 14:09:12 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20format?= =?UTF-8?q?=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_annotated.py | 7 ++++++- tests/test_completion/test_completion_install.py | 3 ++- typer/main.py | 5 ++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test_annotated.py b/tests/test_annotated.py index beb4ce2293..657e2bd6d0 100644 --- a/tests/test_annotated.py +++ b/tests/test_annotated.py @@ -60,8 +60,10 @@ def cmd(force: Annotated[bool, typer.Option("--force")] = False): assert result.exit_code == 0, result.output assert "Forcing operation" in result.output + def test_runner_can_use_an_async_method(): app = typer.Typer() + @app.command() async def cmd(val: Annotated[int, typer.Argument()] = 0): print(f"hello {val}") @@ -74,10 +76,14 @@ async def cmd(val: Annotated[int, typer.Argument()] = 0): assert result.exit_code == 0, result.output assert "hello 42" in result.output + if sys.version_info >= (3, 11): + def test_runner_can_use_a_custom_async_loop(): import asyncio + app = typer.Typer(loop_factory=asyncio.new_event_loop) + @app.command() async def cmd(val: Annotated[int, typer.Argument()] = 0): print(f"hello {val}") @@ -89,4 +95,3 @@ async def cmd(val: Annotated[int, typer.Argument()] = 0): result = runner.invoke(app, ["42"]) assert result.exit_code == 0, result.output assert "hello 42" in result.output - diff --git a/tests/test_completion/test_completion_install.py b/tests/test_completion/test_completion_install.py index 830f5901c9..1a5b5f3833 100644 --- a/tests/test_completion/test_completion_install.py +++ b/tests/test_completion/test_completion_install.py @@ -5,9 +5,9 @@ from unittest import mock import shellingham +from typer.testing import CliRunner from docs_src.commands.index import tutorial001 as mod -from typer.testing import CliRunner runner = CliRunner() app = mod.app @@ -142,6 +142,7 @@ def test_completion_install_fish(): assert "completion installed in" in result.stdout assert "Completion will take effect once you restart the terminal" in result.stdout + def test_completion_install_powershell(): completion_path: Path = ( Path.home() / f".config/powershell/Microsoft.PowerShell_profile.ps1" diff --git a/typer/main.py b/typer/main.py index 039f816f80..0eeedc2ea7 100644 --- a/typer/main.py +++ b/typer/main.py @@ -244,14 +244,14 @@ def add_runner(f: CommandFunctionType) -> CommandFunctionType: @wraps(f) def run_wrapper(*args: Any, **kwargs: Any) -> Any: if sys.version_info >= (3, 11) and self.loop_factory: - with asyncio.Runner(loop_factory=self.loop_factory) as runner: #type: ignore + with asyncio.Runner(loop_factory=self.loop_factory) as runner: # type: ignore return runner.run(f(*args, **kwargs)) elif sys.version_info >= (3, 7): return asyncio.run(f(*args, **kwargs)) else: asyncio.get_event_loop().run_until_complete(f(*args, **kwargs)) - return run_wrapper #type: ignore + return run_wrapper # type: ignore if inspect.iscoroutinefunction(f): callback = add_runner(f) @@ -278,7 +278,6 @@ def run_wrapper(*args: Any, **kwargs: Any) -> Any: ) return f - return decorator def add_typer(