summaryrefslogtreecommitdiff
path: root/gitlab/exceptions.py
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-05-01 20:55:56 +0200
committerNejc Habjan <nejc.habjan@siemens.com>2022-06-06 10:41:26 +0200
commit56280040e415b39ca0e9d032a927f0a39e734b9b (patch)
treec3e1b6d2fb077ef41b1347d49d37636e79d9c1f5 /gitlab/exceptions.py
parent0e3c461a2ad6ade9819db864261a82b357ce5808 (diff)
downloadgitlab-refactor/decouple-cli-from-custom-args.tar.gz
refactor: decouple CLI from custom method argumentsrefactor/decouple-cli-from-custom-args
Diffstat (limited to 'gitlab/exceptions.py')
-rw-r--r--gitlab/exceptions.py17
1 files changed, 6 insertions, 11 deletions
diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py
index 3da399c..c8254ec 100644
--- a/gitlab/exceptions.py
+++ b/gitlab/exceptions.py
@@ -16,7 +16,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import functools
-from typing import Any, Callable, cast, Optional, Type, TYPE_CHECKING, TypeVar, Union
+from typing import Any, Callable, cast, Optional, Type, TYPE_CHECKING, Union
+
+from gitlab.types import F
class GitlabError(Exception):
@@ -286,14 +288,7 @@ class GitlabUnfollowError(GitlabOperationError):
pass
-# For an explanation of how these type-hints work see:
-# https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators
-#
-# The goal here is that functions which get decorated will retain their types.
-__F = TypeVar("__F", bound=Callable[..., Any])
-
-
-def on_http_error(error: Type[Exception]) -> Callable[[__F], __F]:
+def on_http_error(error: Type[Exception]) -> Callable[[F], F]:
"""Manage GitlabHttpError exceptions.
This decorator function can be used to catch GitlabHttpError exceptions
@@ -303,7 +298,7 @@ def on_http_error(error: Type[Exception]) -> Callable[[__F], __F]:
The exception type to raise -- must inherit from GitlabError
"""
- def wrap(f: __F) -> __F:
+ def wrap(f: F) -> F:
@functools.wraps(f)
def wrapped_f(*args: Any, **kwargs: Any) -> Any:
try:
@@ -311,6 +306,6 @@ def on_http_error(error: Type[Exception]) -> Callable[[__F], __F]:
except GitlabHttpError as e:
raise error(e.error_message, e.response_code, e.response_body) from e
- return cast(__F, wrapped_f)
+ return cast(F, wrapped_f)
return wrap