Compare commits

...

2 commits

Author SHA1 Message Date
pre-commit-ci[bot]
8b446f0920 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks 2024-02-12 22:36:29 +00:00
pre-commit-ci[bot]
637a13e0b5
⬆ [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/pycqa/isort: 5.12.0 → 5.13.2](https://github.com/pycqa/isort/compare/5.12.0...5.13.2)
- [github.com/psf/black: 23.10.0 → 24.2.0](https://github.com/psf/black/compare/23.10.0...24.2.0)
2024-02-12 22:36:15 +00:00
5 changed files with 35 additions and 32 deletions

View file

@ -36,7 +36,7 @@ repos:
- __init__.py
- --remove-duplicate-keys
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
@ -47,7 +47,7 @@ repos:
name: isort (pyi)
types: [pyi]
- repo: https://github.com/psf/black
rev: 23.10.0
rev: 24.2.0
hooks:
- id: black
ci:

View file

@ -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)
@ -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)
@ -117,8 +116,9 @@ def test_forbid_default_factory_and_default_value_in_annotated(param, param_info
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)
@ -165,8 +165,9 @@ def test_forbid_default_and_default_factory_with_default_param(param, param_info
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)

View file

@ -237,9 +237,11 @@ else:
# 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
)

View file

@ -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
@ -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(
@ -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
@ -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(

View file

@ -67,9 +67,9 @@ STYLE_ERRORS_SUGGESTION = "dim"
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
@ -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
@ -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(