diff options
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. |