diff options
author | Devaev Maxim <[email protected]> | 2019-06-28 18:59:36 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-06-28 18:59:36 +0300 |
commit | ef3c62a7af520673154233e2d3c89492ffec3195 (patch) | |
tree | 2b78c5918143eff8ef2c89484ac99fc6b7588438 /kvmd/validators | |
parent | ff270591b032cc1f8e342f20a04b84e5dbb31191 (diff) |
f-strings
Diffstat (limited to 'kvmd/validators')
-rw-r--r-- | kvmd/validators/__init__.py | 6 | ||||
-rw-r--r-- | kvmd/validators/basic.py | 8 |
2 files changed, 7 insertions, 7 deletions
diff --git a/kvmd/validators/__init__.py b/kvmd/validators/__init__.py index 5556f564..c1374930 100644 --- a/kvmd/validators/__init__.py +++ b/kvmd/validators/__init__.py @@ -40,13 +40,13 @@ class ValidatorError(ValueError): def raise_error(arg: Any, name: str, hide: bool=False) -> NoReturn: arg_str = " " if not hide: - arg_str = (" %r " if isinstance(arg, (str, bytes)) else " '%s' ") % (arg) - raise ValidatorError("The argument" + arg_str + "is not a valid " + name) + arg_str = (f" {arg!r} " if isinstance(arg, (str, bytes)) else f" '{arg}' ") + raise ValidatorError(f"The argument{arg_str}is not a valid {name}") def check_not_none(arg: Any, name: str) -> Any: if arg is None: - raise ValidatorError("Empty argument is not a valid %s" % (name)) + raise ValidatorError(f"Empty argument is not a valid {name}") return arg diff --git a/kvmd/validators/basic.py b/kvmd/validators/basic.py index 62f9b36d..87056428 100644 --- a/kvmd/validators/basic.py +++ b/kvmd/validators/basic.py @@ -40,7 +40,7 @@ def valid_bool(arg: Any) -> bool: true_args = ["1", "true", "yes"] false_args = ["0", "false", "no"] - name = "bool (%r or %r)" % (true_args, false_args) + name = f"bool ({true_args!r} or {false_args!r})" arg = check_not_none_string(arg, name).lower() arg = check_in_list(arg, name, true_args + false_args) @@ -64,9 +64,9 @@ def valid_number( raise_error(arg, name) if min is not None and arg < min: - raise ValidatorError("The argument '%s' must be %s and greater or equial than %s" % (arg, name, min)) + raise ValidatorError(f"The argument '{arg}' must be {name} and greater or equial than {min}") if max is not None and arg > max: - raise ValidatorError("The argument '%s' must be %s and lesser or equal then %s" % (arg, name, max)) + raise ValidatorError(f"The argument '{arg}' must be {name} and lesser or equal then {max}") return arg @@ -98,5 +98,5 @@ def valid_string_list( try: arg = list(map(subval, arg)) except Exception: - raise ValidatorError("Failed sub-validator on one of the item of %r" % (arg)) + raise ValidatorError(f"Failed sub-validator on one of the item of {arg!r}") return arg |