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

Commitf775668

Browse files
authored
Merge pull request#1691 from python-gitlab/jlvillal/mypy_snippets
chore: add type-hints to gitlab/v4/objects/snippets.py
2 parentsa544cd5 +f256d4f commitf775668

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

‎gitlab/v4/objects/snippets.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
fromtypingimportAny,Callable,cast,List,Optional,TYPE_CHECKING,Union
2+
3+
importrequests
4+
15
fromgitlabimportcli
26
fromgitlabimportexceptionsasexc
37
fromgitlabimportutils
4-
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
8+
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject,RESTObjectList
59
fromgitlab.mixinsimportCRUDMixin,ObjectDeleteMixin,SaveMixin,UserAgentDetailMixin
610

711
from .award_emojisimportProjectSnippetAwardEmojiManager# noqa: F401
@@ -21,7 +25,13 @@ class Snippet(UserAgentDetailMixin, SaveMixin, ObjectDeleteMixin, RESTObject):
2125

2226
@cli.register_custom_action("Snippet")
2327
@exc.on_http_error(exc.GitlabGetError)
24-
defcontent(self,streamed=False,action=None,chunk_size=1024,**kwargs):
28+
defcontent(
29+
self,
30+
streamed:bool=False,
31+
action:Optional[Callable[...,Any]]=None,
32+
chunk_size:int=1024,
33+
**kwargs:Any,
34+
)->Optional[bytes]:
2535
"""Return the content of a snippet.
2636
2737
Args:
@@ -44,6 +54,8 @@ def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
4454
result=self.manager.gitlab.http_get(
4555
path,streamed=streamed,raw=True,**kwargs
4656
)
57+
ifTYPE_CHECKING:
58+
assertisinstance(result,requests.Response)
4759
returnutils.response_content(result,streamed,action,chunk_size)
4860

4961

@@ -58,7 +70,7 @@ class SnippetManager(CRUDMixin, RESTManager):
5870
)
5971

6072
@cli.register_custom_action("SnippetManager")
61-
defpublic(self,**kwargs):
73+
defpublic(self,**kwargs:Any)->Union[RESTObjectList,List[RESTObject]]:
6274
"""List all the public snippets.
6375
6476
Args:
@@ -73,6 +85,9 @@ def public(self, **kwargs):
7385
"""
7486
returnself.list(path="/snippets/public",**kwargs)
7587

88+
defget(self,id:Union[str,int],lazy:bool=False,**kwargs:Any)->Snippet:
89+
returncast(Snippet,super().get(id=id,lazy=lazy,**kwargs))
90+
7691

7792
classProjectSnippet(UserAgentDetailMixin,SaveMixin,ObjectDeleteMixin,RESTObject):
7893
_url="/projects/{project_id}/snippets"
@@ -84,7 +99,13 @@ class ProjectSnippet(UserAgentDetailMixin, SaveMixin, ObjectDeleteMixin, RESTObj
8499

85100
@cli.register_custom_action("ProjectSnippet")
86101
@exc.on_http_error(exc.GitlabGetError)
87-
defcontent(self,streamed=False,action=None,chunk_size=1024,**kwargs):
102+
defcontent(
103+
self,
104+
streamed:bool=False,
105+
action:Optional[Callable[...,Any]]=None,
106+
chunk_size:int=1024,
107+
**kwargs:Any,
108+
)->Optional[bytes]:
88109
"""Return the content of a snippet.
89110
90111
Args:
@@ -107,6 +128,8 @@ def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
107128
result=self.manager.gitlab.http_get(
108129
path,streamed=streamed,raw=True,**kwargs
109130
)
131+
ifTYPE_CHECKING:
132+
assertisinstance(result,requests.Response)
110133
returnutils.response_content(result,streamed,action,chunk_size)
111134

112135

@@ -121,3 +144,8 @@ class ProjectSnippetManager(CRUDMixin, RESTManager):
121144
_update_attrs=RequiredOptional(
122145
optional=("title","file_name","content","visibility","description"),
123146
)
147+
148+
defget(
149+
self,id:Union[str,int],lazy:bool=False,**kwargs:Any
150+
)->ProjectSnippet:
151+
returncast(ProjectSnippet,super().get(id=id,lazy=lazy,**kwargs))

‎pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ module = [
2424
"gitlab.v4.objects.repositories",
2525
"gitlab.v4.objects.services",
2626
"gitlab.v4.objects.sidekiq",
27-
"gitlab.v4.objects.snippets",
2827
"setup",
2928
"tests.functional.*",
3029
"tests.functional.api.*",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp