Skip to content

Commit d04e557

Browse files
chore: add type-hints to gitlab/v4/objects/labels.py
1 parent a91a303 commit d04e557

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

gitlab/v4/objects/labels.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, cast, Dict, Optional, TYPE_CHECKING, Union
2+
13
from gitlab import exceptions as exc
24
from gitlab.base import RequiredOptional, RESTManager, RESTObject
35
from gitlab.mixins import (
@@ -22,10 +24,11 @@
2224

2325
class GroupLabel(SubscribableMixin, SaveMixin, ObjectDeleteMixin, RESTObject):
2426
_id_attr = "name"
27+
manager: "GroupLabelManager"
2528

2629
# Update without ID, but we need an ID to get from list.
2730
@exc.on_http_error(exc.GitlabUpdateError)
28-
def save(self, **kwargs):
31+
def save(self, **kwargs: Any) -> None:
2932
"""Saves the changes made to the object to the server.
3033
3134
The object is updated to match what the server returns.
@@ -56,7 +59,14 @@ class GroupLabelManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
5659
)
5760

5861
# Update without ID.
59-
def update(self, name, new_data=None, **kwargs):
62+
# NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
63+
# type error
64+
def update( # type: ignore
65+
self,
66+
name: Optional[str],
67+
new_data: Optional[Dict[str, Any]] = None,
68+
**kwargs: Any
69+
) -> Dict[str, Any]:
6070
"""Update a Label on the server.
6171
6272
Args:
@@ -70,7 +80,9 @@ def update(self, name, new_data=None, **kwargs):
7080

7181
# Delete without ID.
7282
@exc.on_http_error(exc.GitlabDeleteError)
73-
def delete(self, name, **kwargs):
83+
# NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
84+
# type error
85+
def delete(self, name: str, **kwargs: Any) -> None: # type: ignore
7486
"""Delete a Label on the server.
7587
7688
Args:
@@ -81,17 +93,20 @@ def delete(self, name, **kwargs):
8193
GitlabAuthenticationError: If authentication is not correct
8294
GitlabDeleteError: If the server cannot perform the request
8395
"""
96+
if TYPE_CHECKING:
97+
assert self.path is not None
8498
self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs)
8599

86100

87101
class ProjectLabel(
88102
PromoteMixin, SubscribableMixin, SaveMixin, ObjectDeleteMixin, RESTObject
89103
):
90104
_id_attr = "name"
105+
manager: "ProjectLabelManager"
91106

92107
# Update without ID, but we need an ID to get from list.
93108
@exc.on_http_error(exc.GitlabUpdateError)
94-
def save(self, **kwargs):
109+
def save(self, **kwargs: Any) -> None:
95110
"""Saves the changes made to the object to the server.
96111
97112
The object is updated to match what the server returns.
@@ -123,8 +138,20 @@ class ProjectLabelManager(
123138
required=("name",), optional=("new_name", "color", "description", "priority")
124139
)
125140

141+
def get(
142+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
143+
) -> ProjectLabel:
144+
return cast(ProjectLabel, super().get(id=id, lazy=lazy, **kwargs))
145+
126146
# Update without ID.
127-
def update(self, name, new_data=None, **kwargs):
147+
# NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
148+
# type error
149+
def update( # type: ignore
150+
self,
151+
name: Optional[str],
152+
new_data: Optional[Dict[str, Any]] = None,
153+
**kwargs: Any
154+
) -> Dict[str, Any]:
128155
"""Update a Label on the server.
129156
130157
Args:
@@ -138,7 +165,9 @@ def update(self, name, new_data=None, **kwargs):
138165

139166
# Delete without ID.
140167
@exc.on_http_error(exc.GitlabDeleteError)
141-
def delete(self, name, **kwargs):
168+
# NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
169+
# type error
170+
def delete(self, name: str, **kwargs: Any) -> None: # type: ignore
142171
"""Delete a Label on the server.
143172
144173
Args:
@@ -149,4 +178,6 @@ def delete(self, name, **kwargs):
149178
GitlabAuthenticationError: If authentication is not correct
150179
GitlabDeleteError: If the server cannot perform the request
151180
"""
181+
if TYPE_CHECKING:
182+
assert self.path is not None
152183
self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs)

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module = [
1313
"docs.*",
1414
"docs.ext.*",
1515
"gitlab.v4.objects.files",
16-
"gitlab.v4.objects.labels",
1716
"tests.functional.*",
1817
"tests.functional.api.*",
1918
"tests.meta.*",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy