Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(api): Make RESTManager generic on RESTObject class#3083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletionsgitlab/base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,18 @@
import pprint
import textwrap
from types import ModuleType
from typing import Any, Dict, Iterable, Optional, Type, TYPE_CHECKING, Union
from typing import (
Any,
ClassVar,
Dict,
Generic,
Iterable,
Optional,
Type,
TYPE_CHECKING,
TypeVar,
Union,
)

import gitlab
from gitlab import types as g_types
Expand DownExpand Up@@ -48,11 +59,11 @@ class RESTObject:
_repr_attr: Optional[str] = None
_updated_attrs: Dict[str, Any]
_lazy: bool
manager: "RESTManager"
manager: "RESTManager[Any]"

def __init__(
self,
manager: "RESTManager",
manager: "RESTManager[Any]",
attrs: Dict[str, Any],
*,
created_from_list: bool = False,
Expand DownExpand Up@@ -269,7 +280,7 @@ class RESTObjectList:
"""

def __init__(
self, manager: "RESTManager", obj_cls: Type[RESTObject], _list: GitlabList
self, manager: "RESTManager[Any]", obj_cls: Type[RESTObject], _list: GitlabList
) -> None:
"""Creates an objects list from a GitlabList.

Expand DownExpand Up@@ -335,7 +346,10 @@ def total(self) -> Optional[int]:
return self._list.total


class RESTManager:
TObjCls = TypeVar("TObjCls", bound=RESTObject)


class RESTManager(Generic[TObjCls]):
"""Base class for CRUD operations on objects.

Derived class must define ``_path`` and ``_obj_cls``.
Expand All@@ -346,12 +360,12 @@ class RESTManager:

_create_attrs: g_types.RequiredOptional = g_types.RequiredOptional()
_update_attrs: g_types.RequiredOptional = g_types.RequiredOptional()
_path:Optional[str] = None
_obj_cls:Optional[Type[RESTObject]] = None
_path:ClassVar[str]
_obj_cls:type[TObjCls]
_from_parent_attrs: Dict[str, Any] = {}
_types: Dict[str, Type[g_types.GitlabAttribute]] = {}

_computed_path:Optional[str]
_computed_path: str
_parent: Optional[RESTObject]
_parent_attrs: Dict[str, Any]
gitlab: Gitlab
Expand All@@ -371,12 +385,10 @@ def __init__(self, gl: Gitlab, parent: Optional[RESTObject] = None) -> None:
def parent_attrs(self) -> Optional[Dict[str, Any]]:
return self._parent_attrs

def _compute_path(self, path: Optional[str] = None) ->Optional[str]:
def _compute_path(self, path: Optional[str] = None) -> str:
self._parent_attrs = {}
if path is None:
path = self._path
if path is None:
return None
if self._parent is None or not self._from_parent_attrs:
return path

Expand All@@ -390,5 +402,5 @@ def _compute_path(self, path: Optional[str] = None) -> Optional[str]:
return path.format(**data)

@property
def path(self) ->Optional[str]:
def path(self) -> str:
return self._computed_path
5 changes: 2 additions & 3 deletionsgitlab/client.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -397,11 +397,10 @@ def auth(self) -> None:
The `user` attribute will hold a `gitlab.objects.CurrentUser` object on
success.
"""
# pylint: disable=line-too-long
self.user = self._objects.CurrentUserManager(self).get() # type: ignore[assignment]
self.user = self._objects.CurrentUserManager(self).get()

if hasattr(self.user, "web_url") and hasattr(self.user, "username"):
self._check_url(self.user.web_url, path=self.user.username) # type: ignore[union-attr]
self._check_url(self.user.web_url, path=self.user.username)

def version(self) -> Tuple[str, str]:
"""Returns the version and revision of the gitlab server.
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp