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

+3-11
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

+8-1
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

+2-1
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

+2-1
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

+2-1
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

+2-1
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

+2-1
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

+2-1
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

+2-1
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

+2-1
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",

gitlab/v4/objects/commits.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import gitlab
66
from gitlab import cli
77
from gitlab import exceptions as exc
8-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
8+
from gitlab.base import RESTManager, RESTObject
99
from gitlab.mixins import CreateMixin, ListMixin, RefreshMixin, RetrieveMixin
10+
from gitlab.types import RequiredOptional
1011

1112
from .discussions import ProjectCommitDiscussionManager # noqa: F401
1213

gitlab/v4/objects/deploy_keys.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
from gitlab import cli
66
from gitlab import exceptions as exc
7-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
7+
from gitlab.base import RESTManager, RESTObject
88
from gitlab.mixins import CRUDMixin, ListMixin, ObjectDeleteMixin, SaveMixin
9+
from gitlab.types import RequiredOptional
910

1011
__all__ = [
1112
"DeployKey",

gitlab/v4/objects/deploy_tokens.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from typing import Any, cast, Union
22

33
from gitlab import types
4-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
4+
from gitlab.base import RESTManager, RESTObject
55
from gitlab.mixins import (
66
CreateMixin,
77
DeleteMixin,
88
ListMixin,
99
ObjectDeleteMixin,
1010
RetrieveMixin,
1111
)
12+
from gitlab.types import RequiredOptional
1213

1314
__all__ = [
1415
"DeployToken",

gitlab/v4/objects/deployments.py

+2-1
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 CreateMixin, RetrieveMixin, SaveMixin, UpdateMixin
5+
from gitlab.types import RequiredOptional
56

67
from .merge_requests import ProjectDeploymentMergeRequestManager # noqa: F401
78

gitlab/v4/objects/discussions.py

+2-1
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 CreateMixin, RetrieveMixin, SaveMixin, UpdateMixin
5+
from gitlab.types import RequiredOptional
56

67
from .notes import ( # noqa: F401
78
ProjectCommitDiscussionNoteManager,

gitlab/v4/objects/environments.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from gitlab import cli
66
from gitlab import exceptions as exc
7-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
7+
from gitlab.base import RESTManager, RESTObject
88
from gitlab.mixins import (
99
CreateMixin,
1010
DeleteMixin,
@@ -13,6 +13,7 @@
1313
SaveMixin,
1414
UpdateMixin,
1515
)
16+
from gitlab.types import RequiredOptional
1617

1718
__all__ = [
1819
"ProjectEnvironment",

gitlab/v4/objects/epics.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from gitlab import exceptions as exc
44
from gitlab import types
5-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
5+
from gitlab.base import RESTManager, RESTObject
66
from gitlab.mixins import (
77
CreateMixin,
88
CRUDMixin,
@@ -12,6 +12,7 @@
1212
SaveMixin,
1313
UpdateMixin,
1414
)
15+
from gitlab.types import RequiredOptional
1516

1617
from .events import GroupEpicResourceLabelEventManager # noqa: F401
1718

gitlab/v4/objects/export_import.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Any, cast, Optional, Union
22

3-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
3+
from gitlab.base import RESTManager, RESTObject
44
from gitlab.mixins import CreateMixin, DownloadMixin, GetWithoutIdMixin, RefreshMixin
5+
from gitlab.types import RequiredOptional
56

67
__all__ = [
78
"GroupExport",

gitlab/v4/objects/files.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from gitlab import cli
77
from gitlab import exceptions as exc
88
from gitlab import utils
9-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
9+
from gitlab.base import RESTManager, RESTObject
1010
from gitlab.mixins import (
1111
CreateMixin,
1212
DeleteMixin,
@@ -15,6 +15,7 @@
1515
SaveMixin,
1616
UpdateMixin,
1717
)
18+
from gitlab.types import RequiredOptional
1819

1920
__all__ = [
2021
"ProjectFile",

gitlab/v4/objects/geo_nodes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
from gitlab import cli
44
from gitlab import exceptions as exc
5-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
5+
from gitlab.base import RESTManager, RESTObject
66
from gitlab.mixins import (
77
DeleteMixin,
88
ObjectDeleteMixin,
99
RetrieveMixin,
1010
SaveMixin,
1111
UpdateMixin,
1212
)
13+
from gitlab.types import RequiredOptional
1314

1415
__all__ = [
1516
"GeoNode",

gitlab/v4/objects/groups.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
from gitlab import cli
77
from gitlab import exceptions as exc
88
from gitlab import types
9-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
9+
from gitlab.base import RESTManager, RESTObject
1010
from gitlab.mixins import CRUDMixin, ListMixin, ObjectDeleteMixin, SaveMixin
11+
from gitlab.types import RequiredOptional
1112

1213
from .access_requests import GroupAccessRequestManager # noqa: F401
1314
from .audit_events import GroupAuditEventManager # noqa: F401

gitlab/v4/objects/hooks.py

+2-1
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, NoUpdateMixin, ObjectDeleteMixin, SaveMixin
5+
from gitlab.types import RequiredOptional
56

67
__all__ = [
78
"Hook",

gitlab/v4/objects/issues.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from gitlab import cli
44
from gitlab import exceptions as exc
55
from gitlab import types
6-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
6+
from gitlab.base import RESTManager, RESTObject
77
from gitlab.mixins import (
88
CreateMixin,
99
CRUDMixin,
@@ -18,6 +18,7 @@
1818
TodoMixin,
1919
UserAgentDetailMixin,
2020
)
21+
from gitlab.types import RequiredOptional
2122

2223
from .award_emojis import ProjectIssueAwardEmojiManager # noqa: F401
2324
from .discussions import ProjectIssueDiscussionManager # noqa: F401

gitlab/v4/objects/labels.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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 (
66
CreateMixin,
77
DeleteMixin,
@@ -12,6 +12,7 @@
1212
SubscribableMixin,
1313
UpdateMixin,
1414
)
15+
from gitlab.types import RequiredOptional
1516

1617
__all__ = [
1718
"GroupLabel",

gitlab/v4/objects/members.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, cast, Union
22

33
from gitlab import types
4-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
4+
from gitlab.base import RESTManager, RESTObject
55
from gitlab.mixins import (
66
CRUDMixin,
77
DeleteMixin,
@@ -10,6 +10,7 @@
1010
RetrieveMixin,
1111
SaveMixin,
1212
)
13+
from gitlab.types import RequiredOptional
1314

1415
__all__ = [
1516
"GroupBillableMember",

gitlab/v4/objects/merge_request_approvals.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, cast, Dict, List, Optional, TYPE_CHECKING, 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 (
66
CreateMixin,
77
DeleteMixin,
@@ -11,6 +11,7 @@
1111
SaveMixin,
1212
UpdateMixin,
1313
)
14+
from gitlab.types import RequiredOptional
1415

1516
__all__ = [
1617
"ProjectApproval",

gitlab/v4/objects/merge_requests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from gitlab import cli
1212
from gitlab import exceptions as exc
1313
from gitlab import types
14-
from gitlab.base import RequiredOptional, RESTManager, RESTObject, RESTObjectList
14+
from gitlab.base import RESTManager, RESTObject, RESTObjectList
1515
from gitlab.mixins import (
1616
CRUDMixin,
1717
ListMixin,
@@ -23,6 +23,7 @@
2323
TimeTrackingMixin,
2424
TodoMixin,
2525
)
26+
from gitlab.types import RequiredOptional
2627

2728
from .award_emojis import ProjectMergeRequestAwardEmojiManager # noqa: F401
2829
from .commits import ProjectCommit, ProjectCommitManager

gitlab/v4/objects/milestones.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from gitlab import cli
44
from gitlab import exceptions as exc
55
from gitlab import types
6-
from gitlab.base import RequiredOptional, RESTManager, RESTObject, RESTObjectList
6+
from gitlab.base import RESTManager, RESTObject, RESTObjectList
77
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, PromoteMixin, SaveMixin
8+
from gitlab.types import RequiredOptional
89

910
from .issues import GroupIssue, GroupIssueManager, ProjectIssue, ProjectIssueManager
1011
from .merge_requests import (

0 commit comments

Comments
 (0)