diff options
author | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-05-22 14:20:26 +0200 |
---|---|---|
committer | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-05-22 15:10:13 +0200 |
commit | 055c1920140ebf36501d30307d5ab86965ae185f (patch) | |
tree | 60fc1453b5917e3bbeee18869e87946e1a3ad8df | |
parent | 68107f722b4f70fb64ad2c3126fc5bf1ee0869e4 (diff) | |
download | pylint-git-055c1920140ebf36501d30307d5ab86965ae185f.tar.gz |
Add ``ParamSpec`` to decorator
-rw-r--r-- | pylint/config/_pylint_config/utils.py | 14 | ||||
-rw-r--r-- | tests/config/pylint_config/test_pylint_config_utils.py | 6 |
2 files changed, 13 insertions, 7 deletions
diff --git a/pylint/config/_pylint_config/utils.py b/pylint/config/_pylint_config/utils.py index a905cd12f..77b5491c0 100644 --- a/pylint/config/_pylint_config/utils.py +++ b/pylint/config/_pylint_config/utils.py @@ -14,6 +14,12 @@ if sys.version_info >= (3, 8): else: from typing_extensions import Literal +if sys.version_info >= (3, 10): + from typing import ParamSpec +else: + from typing_extensions import ParamSpec + +_P = ParamSpec("_P") SUPPORTED_FORMATS = {"t", "toml", "i", "ini"} @@ -27,19 +33,19 @@ class InvalidUserInput(Exception): super().__init__(*args) -def should_retry_after_invalid_input(func: Callable[[], str]) -> Callable[[], str]: +def should_retry_after_invalid_input(func: Callable[_P, str]) -> Callable[_P, str]: """Decorator that handles InvalidUserInput exceptions and retries.""" - def inner_function() -> str: + def inner_function(*args: _P.args, **kwargs: _P.kwargs) -> str: called_once = False while True: try: - return func() + return func(*args, **kwargs) except InvalidUserInput as exc: if called_once and exc.input == "exit()": print("Stopping 'pylint-config'.") sys.exit() - print(f"Format should be one of {exc.valid}.") + print(f"Answer should be one of {exc.valid}.") print("Type 'exit()' if you want to exit the program.") called_once = True diff --git a/tests/config/pylint_config/test_pylint_config_utils.py b/tests/config/pylint_config/test_pylint_config_utils.py index 210bcf93b..d41afec1d 100644 --- a/tests/config/pylint_config/test_pylint_config_utils.py +++ b/tests/config/pylint_config/test_pylint_config_utils.py @@ -24,11 +24,11 @@ def test_retrying_user_input_validation( captured = capsys.readouterr() assert ( captured.out - == """Format should be one of i, ini, t, toml. + == """Answer should be one of i, ini, t, toml. Type 'exit()' if you want to exit the program. -Format should be one of i, ini, t, toml. +Answer should be one of i, ini, t, toml. Type 'exit()' if you want to exit the program. -Format should be one of i, ini, t, toml. +Answer should be one of i, ini, t, toml. Type 'exit()' if you want to exit the program. Stopping 'pylint-config'. """ |