Skip to content

Commit 960d746

Browse files
committed
chore(lint): fix linting issues
1 parent 56f8257 commit 960d746

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

kp_pre_commit_hooks/gitops_values_validation.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dataclasses import dataclass, field
55
from functools import cache, cached_property
66
from pathlib import Path
7-
from typing import Iterator, Optional, Sequence, Union, cast
7+
from typing import Iterator, Literal, Mapping, Optional, Sequence, Union, cast
88

99
import requests
1010
import semver
@@ -71,9 +71,12 @@
7171
# Generic Helper functions and classes
7272
###############################################################################
7373

74-
def colorize(text: str, color: str = None, bold: bool = False) -> str:
74+
Color = Literal["black", "grey", "red", "green", "yellow", "blue", "magenta", "cyan"]
75+
Attribute = Literal["bold", "dark", "underline", "blink", "reverse", "concealed"]
76+
77+
def colorize(text: str, color: Color | None = None, bold: bool = False) -> str:
7578
"""Apply color and formatting to text"""
76-
attrs = ["bold"] if bold else None
79+
attrs: list[Attribute] = ["bold"] if bold else []
7780
return colored(text, color, attrs=attrs)
7881

7982
def camel_to_snake(name: str) -> str:
@@ -258,10 +261,10 @@ def helm_chart(self) -> HelmChart:
258261

259262
def sync_values_files_schema_header_version(self) -> None:
260263
"""Sync schema version in all values files"""
264+
if self.helm_chart.platform_managed_chart_version is None:
265+
return
261266
for value_file in self.values_files:
262-
value_file.set_header_schema_version(
263-
self.helm_chart.platform_managed_chart_version
264-
)
267+
value_file.set_header_schema_version(self.helm_chart.platform_managed_chart_version)
265268

266269
class ServiceInstanceConfigValidator:
267270

@@ -410,7 +413,7 @@ def iter_schema_validation_errors(self) -> Iterator[SchemaValidationError]:
410413
)
411414

412415
def enrich_error_message(self, error: ValidationError) -> ValidationError:
413-
if error.message.endswith("is too long") and error.schema.get("maxLength"):
416+
if error.message.endswith("is too long") and isinstance(error.schema, Mapping) and error.schema.get("maxLength"):
414417
error.message += f', the maximum length is {error.schema["maxLength"]}'
415418
return error
416419

@@ -478,8 +481,8 @@ def format_error(error: Union[ValidationError, SchemaValidationError]) -> str:
478481
location = "/".join(map(str, error.absolute_path))
479482
error_message = f"{colorize('ERROR:', 'red')} {error.message}\n at: {colorize(location, bold=True)}"
480483

481-
if description := error.schema and error.schema.get("description"):
482-
title, description = description.split("\n", maxsplit=1)
484+
if isinstance(error.schema, Mapping) and "description" in error.schema:
485+
title, description = error.schema["description"].split("\n", maxsplit=1)
483486
error_message += f"\n\n {colorize('Hint:', bold=True)} {title}\n\n"
484487
error_message += textwrap.indent(description, prefix=" " * 7)
485488

0 commit comments

Comments
 (0)