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 6a107b0 commit f6be1ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 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

7 changes: 4 additions & 3 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path
from traceback import FrameSummary, StackSummary
from types import TracebackType
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union, ParamSpec
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
from uuid import UUID

import click
Expand Down Expand Up @@ -252,7 +252,9 @@ def runner(*args, **kwargs) -> Any:
elif sys.version_info >= (3, 7):
return asyncio.run(f(*args, **kwargs))
else:
asyncio.get_event_loop().run_until_complete(asyncio.wait(f(*args, **kwargs)))
asyncio.get_event_loop().run_until_complete(
asyncio.wait(f(*args, **kwargs))
)

return runner

Expand Down Expand Up @@ -280,7 +282,6 @@ def runner(*args, **kwargs) -> Any:
)
)


return decorator

def add_typer(
Expand Down

0 comments on commit f6be1ea

Please sign in to comment.