diff options
author | Nejc Habjan <nejc.habjan@siemens.com> | 2022-05-01 20:55:56 +0200 |
---|---|---|
committer | Nejc Habjan <nejc.habjan@siemens.com> | 2022-06-06 10:41:26 +0200 |
commit | 56280040e415b39ca0e9d032a927f0a39e734b9b (patch) | |
tree | c3e1b6d2fb077ef41b1347d49d37636e79d9c1f5 /gitlab/base.py | |
parent | 0e3c461a2ad6ade9819db864261a82b357ce5808 (diff) | |
download | gitlab-refactor/decouple-cli-from-custom-args.tar.gz |
refactor: decouple CLI from custom method argumentsrefactor/decouple-cli-from-custom-args
Diffstat (limited to 'gitlab/base.py')
-rw-r--r-- | gitlab/base.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/gitlab/base.py b/gitlab/base.py index 6e7d5c5..1838b4e 100644 --- a/gitlab/base.py +++ b/gitlab/base.py @@ -19,11 +19,12 @@ import importlib import pprint import textwrap from types import ModuleType -from typing import Any, Dict, Iterable, Optional, Type, Union +from typing import Any, Callable, Dict, Iterable, Optional, Type, Union import gitlab from gitlab import types as g_types from gitlab.exceptions import GitlabParsingError +from gitlab.types import F from .client import Gitlab, GitlabList @@ -328,6 +329,28 @@ class RESTObjectList: return self._list.total +def custom_attrs( + required: tuple = (), optional: tuple = (), exclusive: tuple = () +) -> Callable[[F], F]: + """Decorates a custom method to add a RequiredOptional attribute. + + Args: + required: A tuple of API attributes required in the custom method + optional: A tuple of API attributes optional in the custom method + exclusive: A tuple of mutually exclusive API attributes in the custom method + """ + + def decorator(func: F) -> F: + setattr( + func, + "_custom_attrs", + g_types.RequiredOptional(required, optional, exclusive), + ) + return func + + return decorator + + class RESTManager: """Base class for CRUD operations on objects. |