Skip to content

Commit 37eb8e0

Browse files
authored
Merge pull request #2039 from python-gitlab/jlvillal/required_optional
chore: move `RequiredOptional` to the `gitlab.types` module
2 parents 1f17349 + 7d26530 commit 37eb8e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+108
-65
lines changed

gitlab/base.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
import importlib
1919
import pprint
2020
import textwrap
21-
from dataclasses import dataclass
2221
from types import ModuleType
23-
from typing import Any, Dict, Iterable, Optional, Tuple, Type, Union
22+
from typing import Any, Dict, Iterable, Optional, Type, Union
2423

2524
import gitlab
2625
from gitlab import types as g_types
@@ -29,7 +28,6 @@
2928
from .client import Gitlab, GitlabList
3029

3130
__all__ = [
32-
"RequiredOptional",
3331
"RESTObject",
3432
"RESTObjectList",
3533
"RESTManager",
@@ -330,12 +328,6 @@ def total(self) -> Optional[int]:
330328
return self._list.total
331329

332330

333-
@dataclass(frozen=True)
334-
class RequiredOptional:
335-
required: Tuple[str, ...] = ()
336-
optional: Tuple[str, ...] = ()
337-
338-
339331
class RESTManager:
340332
"""Base class for CRUD operations on objects.
341333
@@ -345,8 +337,8 @@ class RESTManager:
345337
``_obj_cls``: The class of objects that will be created
346338
"""
347339

348-
_create_attrs: RequiredOptional = RequiredOptional()
349-
_update_attrs: RequiredOptional = RequiredOptional()
340+
_create_attrs: g_types.RequiredOptional = g_types.RequiredOptional()
341+
_update_attrs: g_types.RequiredOptional = g_types.RequiredOptional()
350342
_path: Optional[str] = None
351343
_obj_cls: Optional[Type[RESTObject]] = None
352344
_from_parent_attrs: Dict[str, Any] = {}

gitlab/types.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18-
from typing import Any, Optional, TYPE_CHECKING
18+
import dataclasses
19+
from typing import Any, Optional, Tuple, TYPE_CHECKING
20+
21+
22+
@dataclasses.dataclass(frozen=True)
23+
class RequiredOptional:
24+
required: Tuple[str, ...] = ()
25+
optional: Tuple[str, ...] = ()
1926

2027

2128
class GitlabAttribute:

gitlab/v4/objects/appearance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import Any, cast, Dict, Optional, Union
22

33
from gitlab import exceptions as exc
4-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
4+
from gitlab.base import RESTManager, RESTObject
55
from gitlab.mixins import GetWithoutIdMixin, SaveMixin, UpdateMixin
6+
from gitlab.types import RequiredOptional
67

78
__all__ = [
89
"ApplicationAppearance",

gitlab/v4/objects/applications.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
1+
from gitlab.base import RESTManager, RESTObject
22
from gitlab.mixins import CreateMixin, DeleteMixin, ListMixin, ObjectDeleteMixin
3+
from gitlab.types import RequiredOptional
34

45
__all__ = [
56
"Application",

gitlab/v4/objects/award_emojis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Any, cast, Union
22

3-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
3+
from gitlab.base import RESTManager, RESTObject
44
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin
5+
from gitlab.types import RequiredOptional
56

67
__all__ = [
78
"GroupEpicAwardEmoji",

gitlab/v4/objects/badges.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Any, cast, Union
22

3-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
3+
from gitlab.base import RESTManager, RESTObject
44
from gitlab.mixins import BadgeRenderMixin, CRUDMixin, ObjectDeleteMixin, SaveMixin
5+
from gitlab.types import RequiredOptional
56

67
__all__ = [
78
"GroupBadge",

gitlab/v4/objects/boards.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Any, cast, Union
22

3-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
3+
from gitlab.base import RESTManager, RESTObject
44
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
5+
from gitlab.types import RequiredOptional
56

67
__all__ = [
78
"GroupBoardList",

gitlab/v4/objects/branches.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Any, cast, Union
22

3-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
3+
from gitlab.base import RESTManager, RESTObject
44
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin
5+
from gitlab.types import RequiredOptional
56

67
__all__ = [
78
"ProjectBranch",

gitlab/v4/objects/broadcast_messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Any, cast, Union
22

3-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
3+
from gitlab.base import RESTManager, RESTObject
44
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
5+
from gitlab.types import RequiredOptional
56

67
__all__ = [
78
"BroadcastMessage",

gitlab/v4/objects/clusters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import Any, cast, Dict, Optional, Union
22

33
from gitlab import exceptions as exc
4-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
4+
from gitlab.base import RESTManager, RESTObject
55
from gitlab.mixins import CreateMixin, CRUDMixin, ObjectDeleteMixin, SaveMixin
6+
from gitlab.types import RequiredOptional
67

78
__all__ = [
89
"GroupCluster",

0 commit comments

Comments
 (0)