fix int formatter
This commit is contained in:
parent
c38ac2da4d
commit
dd08c0aa8d
1 changed files with 6 additions and 5 deletions
|
|
@ -15,6 +15,7 @@ from ytdl_sub.validators.validators import DictValidator
|
||||||
from ytdl_sub.validators.validators import ListValidator
|
from ytdl_sub.validators.validators import ListValidator
|
||||||
from ytdl_sub.validators.validators import LiteralDictValidator
|
from ytdl_sub.validators.validators import LiteralDictValidator
|
||||||
from ytdl_sub.validators.validators import StringValidator
|
from ytdl_sub.validators.validators import StringValidator
|
||||||
|
from ytdl_sub.validators.validators import Validator
|
||||||
|
|
||||||
_fields_validator = re.compile(r"{([a-z][a-z0-9_]*?)}")
|
_fields_validator = re.compile(r"{([a-z][a-z0-9_]*?)}")
|
||||||
|
|
||||||
|
|
@ -122,15 +123,15 @@ class OverridesStringFormatterValidator(StringFormatterValidator):
|
||||||
class OverridesIntegerFormatterValidator(StringFormatterValidator):
|
class OverridesIntegerFormatterValidator(StringFormatterValidator):
|
||||||
_expected_value_type_name = "integer"
|
_expected_value_type_name = "integer"
|
||||||
|
|
||||||
def apply_formatter(self, variable_dict: Dict[str, str]) -> str:
|
def post_process(self, resolved: str) -> str:
|
||||||
output = super().apply_formatter(variable_dict)
|
|
||||||
try:
|
try:
|
||||||
int(output)
|
int(resolved)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise self._validation_exception(
|
raise self._validation_exception(
|
||||||
f"Expected an integer, but received '{output}'"
|
f"Expected an integer, but received '{resolved}'"
|
||||||
) from exc
|
) from exc
|
||||||
return output
|
|
||||||
|
return resolved
|
||||||
|
|
||||||
|
|
||||||
class ListFormatterValidator(ListValidator[StringFormatterValidator]):
|
class ListFormatterValidator(ListValidator[StringFormatterValidator]):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue