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 Mar 18, 2024
1 parent f107389 commit 6aac395
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
21 changes: 11 additions & 10 deletions tests/test_ambiguous_params.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -81,8 +79,9 @@ def test_forbid_multiple_typer_params_in_annotated():
app = typer.Typer()

@app.command()
def cmd(my_param: Annotated[str, typer.Argument(), typer.Argument()]):
... # pragma: no cover
def cmd(
my_param: Annotated[str, typer.Argument(), typer.Argument()]
): ... # pragma: no cover

with pytest.raises(MultipleTyperAnnotationsError) as excinfo:
runner.invoke(app)
Expand Down Expand Up @@ -117,8 +116,9 @@ def make_string():
app = typer.Typer()

@app.command()
def cmd(my_param: Annotated[str, param(default_factory=make_string)] = "hello"):
... # pragma: no cover
def cmd(
my_param: Annotated[str, param(default_factory=make_string)] = "hello"
): ... # pragma: no cover

with pytest.raises(DefaultFactoryAndDefaultValueError) as excinfo:
runner.invoke(app)
Expand Down Expand Up @@ -165,8 +165,9 @@ def make_string():
app = typer.Typer()

@app.command()
def cmd(my_param: str = param("hi", default_factory=make_string)):
... # pragma: no cover
def cmd(
my_param: str = param("hi", default_factory=make_string)
): ... # pragma: no cover

with pytest.raises(DefaultFactoryAndDefaultValueError) as excinfo:
runner.invoke(app)
Expand Down
8 changes: 5 additions & 3 deletions typer/_typing.py
Expand Up @@ -237,9 +237,11 @@ def convert_generics(tp: Type[Any]) -> Type[Any]:

# recursively replace `str` instances inside of `GenericAlias` with `ForwardRef(arg)`
converted = tuple(
ForwardRef(arg)
if isinstance(arg, str) and isinstance(tp, TypingGenericAlias)
else convert_generics(arg)
(
ForwardRef(arg)
if isinstance(arg, str) and isinstance(tp, TypingGenericAlias)
else convert_generics(arg)
)
for arg in args
)

Expand Down
12 changes: 4 additions & 8 deletions typer/params.py
Expand Up @@ -67,8 +67,7 @@ def Option(
path_type: Union[None, Type[str], Type[bytes]] = None,
# Rich settings
rich_help_panel: Union[str, None] = None,
) -> Any:
...
) -> Any: ...


@overload
Expand Down Expand Up @@ -130,8 +129,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(
Expand Down Expand Up @@ -301,8 +299,7 @@ def Argument(
path_type: Union[None, Type[str], Type[bytes]] = None,
# Rich settings
rich_help_panel: Union[str, None] = None,
) -> Any:
...
) -> Any: ...


@overload
Expand Down Expand Up @@ -355,8 +352,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(
Expand Down
22 changes: 13 additions & 9 deletions typer/rich_utils.py
Expand Up @@ -67,9 +67,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
Expand Down Expand Up @@ -205,9 +205,11 @@ def _get_help_text(
if markup_mode != MARKUP_MODE_RICH:
# Remove single linebreaks
remaining_paragraphs = [
x.replace("\n", " ").strip()
if not x.startswith("\b")
else "{}\n".format(x.strip("\b\n"))
(
x.replace("\n", " ").strip()
if not x.startswith("\b")
else "{}\n".format(x.strip("\b\n"))
)
for x in remaining_paragraphs
]
# Join back together
Expand Down Expand Up @@ -265,9 +267,11 @@ def _get_parameter_help(
# Remove single linebreaks
if markup_mode != MARKUP_MODE_MARKDOWN:
paragraphs = [
x.replace("\n", " ").strip()
if not x.startswith("\b")
else "{}\n".format(x.strip("\b\n"))
(
x.replace("\n", " ").strip()
if not x.startswith("\b")
else "{}\n".format(x.strip("\b\n"))
)
for x in paragraphs
]
items.append(
Expand Down

0 comments on commit 6aac395

Please sign in to comment.