Enable Ruff TRY300 (#114437)

* Enable Ruff TRY300

* Update validation.py

* Address review comments
This commit is contained in:
Sid 2024-03-30 10:37:59 +01:00 committed by GitHub
parent 9a79320861
commit 6587ee20db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
97 changed files with 259 additions and 243 deletions

View file

@ -248,13 +248,13 @@ def is_regex(value: Any) -> re.Pattern[Any]:
"""Validate that a string is a valid regular expression."""
try:
r = re.compile(value)
return r
except TypeError as err:
raise vol.Invalid(
f"value {value} is of the wrong type for a regular expression"
) from err
except re.error as err:
raise vol.Invalid(f"value {value} is not a valid regular expression") from err
return r
def isfile(value: Any) -> str:
@ -671,9 +671,9 @@ def template(value: Any | None) -> template_helper.Template:
try:
template_value.ensure_valid()
return template_value
except TemplateError as ex:
raise vol.Invalid(f"invalid template ({ex})") from ex
return template_value
def dynamic_template(value: Any | None) -> template_helper.Template:
@ -693,9 +693,9 @@ def dynamic_template(value: Any | None) -> template_helper.Template:
try:
template_value.ensure_valid()
return template_value
except TemplateError as ex:
raise vol.Invalid(f"invalid template ({ex})") from ex
return template_value
def template_complex(value: Any) -> Any: