refactor(cli): target ruff 310 (#32985)

Use union types for optional parameters
This commit is contained in:
Mason Daugherty
2025-09-16 22:04:28 -04:00
committed by GitHub
parent ab1b822523
commit 66041a2778
5 changed files with 27 additions and 31 deletions

View File

@@ -5,7 +5,7 @@ import subprocess
import sys
import warnings
from pathlib import Path
from typing import Annotated, Optional
from typing import Annotated
import typer
import uvicorn
@@ -35,18 +35,18 @@ app_cli = typer.Typer(no_args_is_help=True, add_completion=False)
@app_cli.command()
def new(
name: Annotated[
Optional[str],
str | None,
typer.Argument(
help="The name of the folder to create",
),
] = None,
*,
package: Annotated[
Optional[list[str]],
list[str] | None,
typer.Option(help="Packages to seed the project with"),
] = None,
pip: Annotated[
Optional[bool],
bool | None,
typer.Option(
"--pip/--no-pip",
help="Pip install the template(s) as editable dependencies",
@@ -127,24 +127,24 @@ def new(
@app_cli.command()
def add(
dependencies: Annotated[
Optional[list[str]],
list[str] | None,
typer.Argument(help="The dependency to add"),
] = None,
*,
api_path: Annotated[
Optional[list[str]],
list[str] | None,
typer.Option(help="API paths to add"),
] = None,
project_dir: Annotated[
Optional[Path],
Path | None,
typer.Option(help="The project directory"),
] = None,
repo: Annotated[
Optional[list[str]],
list[str] | None,
typer.Option(help="Install templates from a specific github repo instead"),
] = None,
branch: Annotated[
Optional[list[str]],
list[str] | None,
typer.Option(help="Install templates from a specific branch"),
] = None,
pip: Annotated[
@@ -186,7 +186,7 @@ def add(
)
# group by repo/ref
grouped: dict[tuple[str, Optional[str]], list[DependencySource]] = {}
grouped: dict[tuple[str, str | None], list[DependencySource]] = {}
for dep in parsed_deps:
key_tup = (dep["git"], dep["ref"])
lst = grouped.get(key_tup, [])
@@ -305,7 +305,7 @@ def remove(
api_paths: Annotated[list[str], typer.Argument(help="The API paths to remove")],
*,
project_dir: Annotated[
Optional[Path],
Path | None,
typer.Option(help="The project directory"),
] = None,
) -> None:
@@ -344,15 +344,15 @@ def remove(
def serve(
*,
port: Annotated[
Optional[int],
int | None,
typer.Option(help="The port to run the server on"),
] = None,
host: Annotated[
Optional[str],
str | None,
typer.Option(help="The host to run the server on"),
] = None,
app: Annotated[
Optional[str],
str | None,
typer.Option(help="The app to run, e.g. `app.server:app`"),
] = None,
) -> None: