Skip to content

Commit

Permalink
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Jul 6, 2023
1 parent af67b42 commit 6031b33
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion tests/test_annotated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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}")
Expand All @@ -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

3 changes: 2 additions & 1 deletion tests/test_completion/test_completion_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def command(
cls = TyperCommand

def decorator(f: CommandFunctionType) -> CommandFunctionType:
def add_runner(f: CommandFunctionType) -> CommandFunctionType: #type: ignore
def add_runner(f: CommandFunctionType) -> CommandFunctionType: # type: ignore
@wraps(f)
def run_wrapper(*args, **kwargs) -> Any:
if sys.version_info >= (3, 11) and self.loop_factory:
Expand All @@ -251,7 +251,7 @@ def run_wrapper(*args, **kwargs) -> Any:
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)
Expand All @@ -278,7 +278,6 @@ def run_wrapper(*args, **kwargs) -> Any:
)
return f


return decorator

def add_typer(
Expand Down

0 comments on commit 6031b33

Please sign in to comment.