Skip to content

Commit 39fdcf0

Browse files
authored
Merge pull request #106 from opsmill/pog-ruf-ruleset
Correct autofixable ruff violations
2 parents be17bc3 + c12afcc commit 39fdcf0

File tree

10 files changed

+18
-23
lines changed

10 files changed

+18
-23
lines changed

infrahub_sdk/_importer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def import_module(
2727
try:
2828
module = importlib.import_module(module_name)
2929
except ModuleNotFoundError as exc:
30-
raise ModuleImportError(message=f"{str(exc)} ({module_path})") from exc
30+
raise ModuleImportError(message=f"{exc!s} ({module_path})") from exc
3131
except SyntaxError as exc:
3232
raise ModuleImportError(message=str(exc)) from exc
3333

infrahub_sdk/ctl/check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async def run_check(
123123
log.error(f" {log_message['message']}")
124124

125125
except QueryNotFoundError as exc:
126-
log.warning(f"{module_name}::{check}: unable to find query ({str(exc)})")
126+
log.warning(f"{module_name}::{check}: unable to find query ({exc!s})")
127127
passed = False
128128
except Exception as exc: # pylint: disable=broad-exception-caught
129129
log.warning(f"{module_name}::{check}: An error occurred during execution ({exc})")

infrahub_sdk/ctl/cli_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def transform(
366366

367367
@app.command(name="protocols")
368368
@catch_exception(console=console)
369-
def protocols( # noqa: PLR0915
369+
def protocols(
370370
schemas: list[Path] = typer.Option(None, help="List of schemas or directory to load."),
371371
branch: str = typer.Option(None, help="Branch of schema to export Python protocols for."),
372372
sync: bool = typer.Option(False, help="Generate for sync or async."),

infrahub_sdk/ctl/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,38 @@ def handle_exception(exc: Exception, console: Console, exit_code: int) -> NoRetu
4848
if isinstance(exc, Exit):
4949
raise typer.Exit(code=exc.exit_code)
5050
if isinstance(exc, AuthenticationError):
51-
console.print(f"[red]Authentication failure: {str(exc)}")
51+
console.print(f"[red]Authentication failure: {exc!s}")
5252
raise typer.Exit(code=exit_code)
5353
if isinstance(exc, (ServerNotReachableError, ServerNotResponsiveError)):
54-
console.print(f"[red]{str(exc)}")
54+
console.print(f"[red]{exc!s}")
5555
raise typer.Exit(code=exit_code)
5656
if isinstance(exc, HTTPError):
57-
console.print(f"[red]HTTP communication failure: {str(exc)} on {exc.request.method} to {exc.request.url}")
57+
console.print(f"[red]HTTP communication failure: {exc!s} on {exc.request.method} to {exc.request.url}")
5858
raise typer.Exit(code=exit_code)
5959
if isinstance(exc, GraphQLError):
6060
print_graphql_errors(console=console, errors=exc.errors)
6161
raise typer.Exit(code=exit_code)
6262
if isinstance(exc, (SchemaNotFoundError, NodeNotFoundError)):
63-
console.print(f"[red]Error: {str(exc)}")
63+
console.print(f"[red]Error: {exc!s}")
6464
raise typer.Exit(code=exit_code)
6565

66-
console.print(f"[red]Error: {str(exc)}")
66+
console.print(f"[red]Error: {exc!s}")
6767
console.print(traceback.format_exc())
6868
raise typer.Exit(code=exit_code)
6969

7070

7171
def catch_exception(
7272
console: Optional[Console] = None, exit_code: int = 1
73-
) -> Callable[[Callable[..., T]], Callable[..., Union[T, Coroutine[Any, Any, T], NoReturn]]]:
73+
) -> Callable[[Callable[..., T]], Callable[..., Union[T, Coroutine[Any, Any, T]]]]:
7474
"""Decorator to handle exception for commands."""
7575
if not console:
7676
console = Console()
7777

78-
def decorator(func: Callable[..., T]) -> Callable[..., Union[T, Coroutine[Any, Any, T], NoReturn]]:
78+
def decorator(func: Callable[..., T]) -> Callable[..., Union[T, Coroutine[Any, Any, T]]]:
7979
if asyncio.iscoroutinefunction(func):
8080

8181
@wraps(func)
82-
async def async_wrapper(*args: Any, **kwargs: Any) -> Union[T, NoReturn]:
82+
async def async_wrapper(*args: Any, **kwargs: Any) -> T:
8383
try:
8484
return await func(*args, **kwargs)
8585
except (Error, Exception) as exc: # pylint: disable=broad-exception-caught
@@ -88,7 +88,7 @@ async def async_wrapper(*args: Any, **kwargs: Any) -> Union[T, NoReturn]:
8888
return async_wrapper
8989

9090
@wraps(func)
91-
def wrapper(*args: Any, **kwargs: Any) -> Union[T, NoReturn]:
91+
def wrapper(*args: Any, **kwargs: Any) -> T:
9292
try:
9393
return func(*args, **kwargs)
9494
except (Error, Exception) as exc: # pylint: disable=broad-exception-caught

infrahub_sdk/graphql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ def render_query_block(data: dict, offset: int = 4, indentation: int = 4) -> lis
4848
elif isinstance(value, dict) and len(value) == 1 and ALIAS_KEY in value and value[ALIAS_KEY]:
4949
lines.append(f"{offset_str}{value[ALIAS_KEY]}: {key}")
5050
elif isinstance(value, dict):
51-
if ALIAS_KEY in value and value[ALIAS_KEY]:
51+
if value.get(ALIAS_KEY):
5252
key_str = f"{value[ALIAS_KEY]}: {key}"
5353
else:
5454
key_str = key
5555

56-
if FILTERS_KEY in value and value[FILTERS_KEY]:
56+
if value.get(FILTERS_KEY):
5757
filters_str = ", ".join(
5858
[f"{key2}: {convert_to_graphql_as_string(value2)}" for key2, value2 in value[FILTERS_KEY].items()]
5959
)

infrahub_sdk/pytest_plugin/items/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
)
1414

1515
__all__ = [
16-
"InfrahubItem",
1716
"InfrahubCheckIntegrationItem",
1817
"InfrahubCheckSmokeItem",
1918
"InfrahubCheckUnitProcessItem",
2019
"InfrahubGraphQLQueryIntegrationItem",
2120
"InfrahubGraphQLQuerySmokeItem",
21+
"InfrahubItem",
2222
"InfrahubJinja2TransformIntegrationItem",
2323
"InfrahubJinja2TransformSmokeItem",
2424
"InfrahubJinja2TransformUnitRenderItem",

infrahub_sdk/query_groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _get_params_as_str(self) -> str:
4949
"""Convert the params in dict format, into a string"""
5050
params_as_str: list[str] = []
5151
for key, value in self.params.items():
52-
params_as_str.append(f"{key}: {str(value)}")
52+
params_as_str.append(f"{key}: {value!s}")
5353
return ", ".join(params_as_str)
5454

5555
def _generate_group_name(self, suffix: Optional[str] = None) -> str:

pyproject.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,8 @@ ignore = [
250250
"PTH109", # `os.getcwd()` should be replaced by `Path.cwd()`
251251
"RET504", # Unnecessary assignment to `data` before `return` statement
252252
"RUF005", # Consider `[*path, str(key)]` instead of concatenation
253-
"RUF010", # [*] Use explicit conversion flag
254253
"RUF015", # Prefer `next(iter(input_data["variables"].keys()))` over single element slice
255-
"RUF019", # [*] Unnecessary key check before dictionary access
256-
"RUF020", # [*] `Union[NoReturn, T]` is equivalent to `T`
257-
"RUF022", # [*] `__all__` is not sorted
258254
"RUF029", # Function is declared `async`, but doesn't `await` or use `async` features.
259-
"RUF100", # [*] Unused `noqa` directive
260255
"S108", # Probable insecure usage of temporary file or directory
261256
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
262257
"S701", # By default, jinja2 sets `autoescape` to `False`. Consider using `autoescape=True`

tests/integration/test_export_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def schema(self, schema_car_base, schema_pool_base, schema_manufacturer_base) ->
409409
}
410410

411411
@pytest.fixture(scope="class")
412-
async def initial_dataset(self, client: InfrahubClient, schema): # noqa: PLR0914
412+
async def initial_dataset(self, client: InfrahubClient, schema):
413413
await client.schema.load(schemas=[schema])
414414

415415
bmw = await client.create(

tests/unit/sdk/test_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,5 +310,5 @@ async def test_display_schema_load_errors_details_namespace(mock_get_node):
310310
output = console.file.getvalue()
311311
expected_console = """Unable to load the schema:
312312
Node: OuTInstance | namespace (OuT) | String should match pattern '^[A-Z]+$' (string_pattern_mismatch)
313-
""" # noqa: E501
313+
"""
314314
assert output == expected_console

0 commit comments

Comments
 (0)