Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68e8c0d

Browse files
committed
Minor fixes to make pre-commit happy
1 parent bd64572 commit 68e8c0d

File tree

7 files changed

+52
-60
lines changed

7 files changed

+52
-60
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 40 deletions
This file was deleted.

gitlab/base.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@
1919
import pprint
2020
import textwrap
2121
from types import ModuleType
22-
from typing import Any, Dict, Generic, Iterable, Iterator, Optional, Collection, Type, TypeVar, Union
22+
from typing import (
23+
Any,
24+
Dict,
25+
Generic,
26+
Iterable,
27+
Iterator,
28+
Optional,
29+
Type,
30+
TypeVar,
31+
Union,
32+
)
2333

2434
import gitlab
2535
from gitlab import types as g_types
@@ -245,8 +255,10 @@ def attributes(self) -> Dict[str, Any]:
245255
d.update(self.__dict__["_parent_attrs"])
246256
return d
247257

258+
248259
T = TypeVar("T", bound=RESTObject)
249260

261+
250262
class RESTObjectList(Generic[T], Iterable[T]):
251263
"""Generator object representing a list of RESTObject's.
252264
@@ -328,9 +340,11 @@ def total(self) -> Optional[int]:
328340
"""The total number of items."""
329341
return self._list.total
330342

343+
331344
T_obj = TypeVar("T_obj", bound=RESTObject)
332345
T_parent = TypeVar("T_parent", bound=Optional[RESTObject])
333346

347+
334348
class RESTManager(Generic[T_obj, T_parent]):
335349
"""Base class for CRUD operations on objects.
336350

gitlab/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ def http_list(
815815
as_list: Optional[bool] = None, # Deprecated in favor of `iterator`
816816
iterator: Optional[bool] = None,
817817
**kwargs: Any,
818-
) -> Union[GitlabList, List[Dict[str, int]]]:
818+
) -> Union["GitlabList", List[Dict[str, int]]]:
819819
"""Make a GET request to the Gitlab server for list-oriented queries.
820820
821821
Args:

gitlab/mixins.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
Callable,
2222
Dict,
2323
Generic,
24-
List,
25-
Optional,
2624
Iterable,
25+
Optional,
2726
Tuple,
2827
Type,
29-
TypeVar,
3028
TYPE_CHECKING,
29+
TypeVar,
3130
Union,
3231
)
3332

@@ -62,16 +61,22 @@
6261
"BadgeRenderMixin",
6362
]
6463

64+
T_obj = TypeVar("T_obj", bound=base.RESTObject)
65+
T_parent = TypeVar("T_parent", bound=Optional[base.RESTObject])
66+
6567
if TYPE_CHECKING:
6668
# When running mypy we use these as the base classes
6769
_RestManagerBase = base.RESTManager
6870
_RestObjectBase = base.RESTObject
6971
else:
70-
_RestManagerBase = object
71-
_RestObjectBase = object
7272

73-
T_obj = TypeVar("T_obj", bound=base.RESTObject)
74-
T_parent = TypeVar("T_parent", bound=Optional[base.RESTObject])
73+
class _RestManagerBase(Generic[T_obj, T_parent]):
74+
_obj_cls: Type[T_obj]
75+
_parent: Optional[T_parent]
76+
77+
class _RestObjectBase(Generic[T_obj, T_parent]):
78+
_obj_cls: Type[T_obj]
79+
_parent: Optional[T_parent]
7580

7681

7782
class GetMixin(_RestManagerBase[T_obj, T_parent], Generic[T_obj, T_parent]):
@@ -83,9 +88,7 @@ class GetMixin(_RestManagerBase[T_obj, T_parent], Generic[T_obj, T_parent]):
8388
gitlab: gitlab.Gitlab
8489

8590
@exc.on_http_error(exc.GitlabGetError)
86-
def get(
87-
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
88-
) -> T_obj:
91+
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> T_obj:
8992
"""Retrieve a single object.
9093
9194
Args:
@@ -234,7 +237,9 @@ def list(self, **kwargs: Any) -> Iterable[T_obj]:
234237
return base.RESTObjectList(self, self._obj_cls, obj)
235238

236239

237-
class RetrieveMixin(ListMixin[T_obj, T_parent], GetMixin[T_obj, T_parent], Generic[T_obj, T_parent]):
240+
class RetrieveMixin(
241+
ListMixin[T_obj, T_parent], GetMixin[T_obj, T_parent], Generic[T_obj, T_parent]
242+
):
238243
_computed_path: Optional[str]
239244
_from_parent_attrs: Dict[str, Any]
240245
_parent_attrs: Dict[str, Any]
@@ -407,15 +412,28 @@ def delete(self, id: Optional[Union[str, int]] = None, **kwargs: Any) -> None:
407412
self.gitlab.http_delete(path, **kwargs)
408413

409414

410-
class CRUDMixin(GetMixin[T_obj, T_parent], ListMixin[T_obj, T_parent], CreateMixin[T_obj, T_parent], UpdateMixin[T_obj, T_parent], DeleteMixin[T_obj, T_parent], Generic[T_obj, T_parent]):
415+
class CRUDMixin(
416+
GetMixin[T_obj, T_parent],
417+
ListMixin[T_obj, T_parent],
418+
CreateMixin[T_obj, T_parent],
419+
UpdateMixin[T_obj, T_parent],
420+
DeleteMixin[T_obj, T_parent],
421+
Generic[T_obj, T_parent],
422+
):
411423
_computed_path: Optional[str]
412424
_from_parent_attrs: Dict[str, Any]
413425
_parent_attrs: Dict[str, Any]
414426
_path: Optional[str]
415427
gitlab: gitlab.Gitlab
416428

417429

418-
class NoUpdateMixin(GetMixin[T_obj, T_parent], ListMixin[T_obj, T_parent], CreateMixin[T_obj, T_parent], DeleteMixin[T_obj, T_parent], Generic[T_obj, T_parent]):
430+
class NoUpdateMixin(
431+
GetMixin[T_obj, T_parent],
432+
ListMixin[T_obj, T_parent],
433+
CreateMixin[T_obj, T_parent],
434+
DeleteMixin[T_obj, T_parent],
435+
Generic[T_obj, T_parent],
436+
):
419437
_computed_path: Optional[str]
420438
_from_parent_attrs: Dict[str, Any]
421439
_parent_attrs: Dict[str, Any]

gitlab/v4/objects/milestones.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from gitlab import cli
44
from gitlab import exceptions as exc
55
from gitlab import types
6-
from gitlab.client import GitlabList
76
from gitlab.base import RESTManager, RESTObject, RESTObjectList
7+
from gitlab.client import GitlabList
88
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, PromoteMixin, SaveMixin
99
from gitlab.types import RequiredOptional
1010

gitlab/v4/objects/snippets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import Any, Callable, cast, Iterable, List, Optional, TYPE_CHECKING, Union
1+
from typing import Any, Callable, cast, Iterable, Optional, TYPE_CHECKING, Union
22

33
import requests
44

55
from gitlab import cli
66
from gitlab import exceptions as exc
77
from gitlab import utils
8-
from gitlab.base import RESTManager, RESTObject, RESTObjectList
8+
from gitlab.base import RESTManager, RESTObject
99
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin, UserAgentDetailMixin
1010
from gitlab.types import RequiredOptional
1111

gitlab/v4/objects/users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
https://docs.gitlab.com/ee/api/users.html
44
https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
55
"""
6-
from typing import Any, cast, Dict, Iterable, List, Optional, Union
6+
from typing import Any, cast, Dict, Iterable, Optional, Union
77

88
import requests
99

1010
from gitlab import cli
1111
from gitlab import exceptions as exc
1212
from gitlab import types
13-
from gitlab.base import RESTManager, RESTObject, RESTObjectList
13+
from gitlab.base import RESTManager, RESTObject
1414
from gitlab.mixins import (
1515
CreateMixin,
1616
CRUDMixin,

0 commit comments

Comments
 (0)