Skip to content

Commit 2cf9c3b

Browse files
authored
Merge pull request #646 from opsmill/pog-ruff-up045-20251118-to-infrahub-develop
Correct autofixable ruff rules for Optional
2 parents e39957b + 26d981c commit 2cf9c3b

File tree

10 files changed

+26
-33
lines changed

10 files changed

+26
-33
lines changed

infrahub_sdk/ctl/check.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from asyncio import run as aiorun
66
from dataclasses import dataclass
77
from pathlib import Path
8-
from typing import TYPE_CHECKING, Optional
8+
from typing import TYPE_CHECKING
99

1010
import typer
1111
from rich.console import Console
@@ -49,8 +49,8 @@ def run(
4949
format_json: bool,
5050
list_available: bool,
5151
variables: dict[str, str],
52-
name: Optional[str] = None,
53-
branch: Optional[str] = None,
52+
name: str | None = None,
53+
branch: str | None = None,
5454
) -> None:
5555
"""Locate and execute all checks under the defined path."""
5656

infrahub_sdk/ctl/cli_commands.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sys
99
from collections.abc import Callable
1010
from pathlib import Path
11-
from typing import TYPE_CHECKING, Any, Optional
11+
from typing import TYPE_CHECKING, Any
1212

1313
import typer
1414
import ujson
@@ -78,13 +78,13 @@
7878
@catch_exception(console=console)
7979
def check(
8080
check_name: str = typer.Argument(default="", help="Name of the Python check"),
81-
branch: Optional[str] = None,
81+
branch: str | None = None,
8282
path: str = typer.Option(".", help="Root directory"),
8383
debug: bool = False,
8484
format_json: bool = False,
8585
_: str = CONFIG_PARAM,
8686
list_available: bool = typer.Option(False, "--list", help="Show available Python checks"),
87-
variables: Optional[list[str]] = typer.Argument(
87+
variables: list[str] | None = typer.Argument(
8888
None, help="Variables to pass along with the query. Format key=value key=value."
8989
),
9090
) -> None:
@@ -106,12 +106,12 @@ def check(
106106
@catch_exception(console=console)
107107
async def generator(
108108
generator_name: str = typer.Argument(default="", help="Name of the Generator"),
109-
branch: Optional[str] = None,
109+
branch: str | None = None,
110110
path: str = typer.Option(".", help="Root directory"),
111111
debug: bool = False,
112112
_: str = CONFIG_PARAM,
113113
list_available: bool = typer.Option(False, "--list", help="Show available Generators"),
114-
variables: Optional[list[str]] = typer.Argument(
114+
variables: list[str] | None = typer.Argument(
115115
None, help="Variables to pass along with the query. Format key=value key=value."
116116
),
117117
) -> None:
@@ -134,13 +134,13 @@ async def run(
134134
debug: bool = False,
135135
_: str = CONFIG_PARAM,
136136
branch: str = typer.Option(None, help="Branch on which to run the script."),
137-
concurrent: Optional[int] = typer.Option(
137+
concurrent: int | None = typer.Option(
138138
None,
139139
help="Maximum number of requests to execute at the same time.",
140140
envvar="INFRAHUB_MAX_CONCURRENT_EXECUTION",
141141
),
142142
timeout: int = typer.Option(60, help="Timeout in sec", envvar="INFRAHUB_TIMEOUT"),
143-
variables: Optional[list[str]] = typer.Argument(
143+
variables: list[str] | None = typer.Argument(
144144
None, help="Variables to pass along with the query. Format key=value key=value."
145145
),
146146
) -> None:
@@ -251,7 +251,7 @@ async def _run_transform(
251251
@catch_exception(console=console)
252252
async def render(
253253
transform_name: str = typer.Argument(default="", help="Name of the Python transformation", show_default=False),
254-
variables: Optional[list[str]] = typer.Argument(
254+
variables: list[str] | None = typer.Argument(
255255
None, help="Variables to pass along with the query. Format key=value key=value."
256256
),
257257
branch: str = typer.Option(None, help="Branch on which to render the transform."),
@@ -301,7 +301,7 @@ async def render(
301301
@catch_exception(console=console)
302302
def transform(
303303
transform_name: str = typer.Argument(default="", help="Name of the Python transformation", show_default=False),
304-
variables: Optional[list[str]] = typer.Argument(
304+
variables: list[str] | None = typer.Argument(
305305
None, help="Variables to pass along with the query. Format key=value key=value."
306306
),
307307
branch: str = typer.Option(None, help="Branch on which to run the transformation"),

infrahub_sdk/ctl/generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from typing import TYPE_CHECKING, Optional
4+
from typing import TYPE_CHECKING
55

66
import typer
77
from rich.console import Console
@@ -22,7 +22,7 @@ async def run(
2222
debug: bool,
2323
list_available: bool,
2424
branch: str | None = None,
25-
variables: Optional[list[str]] = None,
25+
variables: list[str] | None = None,
2626
) -> None:
2727
init_logging(debug=debug)
2828
repository_config = get_repository_config(find_repository_config_file())

infrahub_sdk/ctl/graphql.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import ast
44
from collections import defaultdict
55
from pathlib import Path
6-
from typing import Optional
76

87
import typer
98
from ariadne_codegen.client_generators.package import PackageGenerator, get_package_generator
@@ -115,7 +114,7 @@ async def export_schema(
115114
@app.command()
116115
@catch_exception(console=console)
117116
async def generate_return_types(
118-
query: Optional[Path] = typer.Argument(
117+
query: Path | None = typer.Argument(
119118
None, help="Location of the GraphQL query file(s). Defaults to current directory if not specified."
120119
),
121120
schema: Path = typer.Option("schema.graphql", help="Path to the GraphQL schema file."),

infrahub_sdk/ctl/importer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from asyncio import run as aiorun
44
from pathlib import Path
5-
from typing import Optional
65

76
import typer
87
from rich.console import Console
@@ -27,7 +26,7 @@ def load(
2726
quiet: bool = typer.Option(False, help="No console output"),
2827
_: str = CONFIG_PARAM,
2928
branch: str = typer.Option(None, help="Branch from which to export"),
30-
concurrent: Optional[int] = typer.Option(
29+
concurrent: int | None = typer.Option(
3130
None,
3231
help="Maximum number of requests to execute at the same time.",
3332
envvar="INFRAHUB_MAX_CONCURRENT_EXECUTION",

infrahub_sdk/ctl/repository.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import asyncio
44
from pathlib import Path
5-
from typing import Optional
65

76
import typer
87
import yaml
@@ -109,7 +108,7 @@ async def add(
109108
name: str,
110109
location: str,
111110
description: str = "",
112-
username: Optional[str] = None,
111+
username: str | None = None,
113112
password: str = "",
114113
ref: str = "",
115114
read_only: bool = False,
@@ -155,7 +154,7 @@ async def add(
155154

156155
@app.command()
157156
async def list(
158-
branch: Optional[str] = typer.Option(None, help="Branch on which to list repositories."),
157+
branch: str | None = typer.Option(None, help="Branch on which to list repositories."),
159158
debug: bool = False,
160159
_: str = CONFIG_PARAM,
161160
) -> None:
@@ -214,12 +213,12 @@ async def init(
214213
default="https://github.com/opsmill/infrahub-template.git",
215214
help="Template to use for the new repository. Can be a local path or a git repository URL.",
216215
),
217-
data: Optional[Path] = typer.Option(default=None, help="Path to YAML file containing answers to CLI prompt."),
218-
vcs_ref: Optional[str] = typer.Option(
216+
data: Path | None = typer.Option(default=None, help="Path to YAML file containing answers to CLI prompt."),
217+
vcs_ref: str | None = typer.Option(
219218
default="HEAD",
220219
help="VCS reference to use for the template. Defaults to HEAD.",
221220
),
222-
trust: Optional[bool] = typer.Option(
221+
trust: bool | None = typer.Option(
223222
default=False,
224223
help="Trust the template repository. If set, the template will be cloned without verification.",
225224
),

infrahub_sdk/ctl/task.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
from typing import Optional
4-
53
import typer
64
from rich.console import Console
75
from rich.table import Table
@@ -75,8 +73,8 @@ async def list_tasks(
7573
state: list[str] = typer.Option(
7674
None, "--state", "-s", help="Filter by task state. Can be provided multiple times."
7775
),
78-
limit: Optional[int] = typer.Option(None, help="Maximum number of tasks to retrieve."),
79-
offset: Optional[int] = typer.Option(None, help="Offset for pagination."),
76+
limit: int | None = typer.Option(None, help="Maximum number of tasks to retrieve."),
77+
offset: int | None = typer.Option(None, help="Offset for pagination."),
8078
include_related_nodes: bool = typer.Option(False, help="Include related nodes in the output."),
8179
include_logs: bool = typer.Option(False, help="Include task logs in the output."),
8280
json_output: bool = typer.Option(False, "--json", help="Output the result as JSON."),

infrahub_sdk/ctl/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections.abc import Callable, Coroutine
77
from functools import wraps
88
from pathlib import Path
9-
from typing import TYPE_CHECKING, Any, NoReturn, Optional, TypeVar
9+
from typing import TYPE_CHECKING, Any, NoReturn, TypeVar
1010

1111
import typer
1212
from click.exceptions import Exit
@@ -149,7 +149,7 @@ def print_graphql_errors(console: Console, errors: list) -> None:
149149
console.print(f"[red]{escape(str(error))}")
150150

151151

152-
def parse_cli_vars(variables: Optional[list[str]]) -> dict[str, str]:
152+
def parse_cli_vars(variables: list[str] | None) -> dict[str, str]:
153153
if not variables:
154154
return {}
155155

infrahub_sdk/ctl/validate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import sys
44
from pathlib import Path
5-
from typing import Optional
65

76
import typer
87
import ujson
@@ -58,7 +57,7 @@ async def validate_schema(schema: Path, _: str = CONFIG_PARAM) -> None:
5857
@catch_exception(console=console)
5958
def validate_graphql(
6059
query: str,
61-
variables: Optional[list[str]] = typer.Argument(
60+
variables: list[str] | None = typer.Argument(
6261
None, help="Variables to pass along with the query. Format key=value key=value."
6362
),
6463
debug: bool = typer.Option(False, help="Display more troubleshooting information."),

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ ignore = [
210210
"SIM114", # Combine `if` branches using logical `or` operator
211211
"TC003", # Move standard library import `collections.abc.Iterable` into a type-checking block
212212
"UP031", # Use format specifiers instead of percent format
213-
"UP045", # Use `X | None` for type annotations
214213
]
215214

216215

0 commit comments

Comments
 (0)