1
+ from typing import Any , Callable , cast , List , Optional , TYPE_CHECKING , Union
2
+
3
+ import requests
4
+
1
5
from gitlab import cli
2
6
from gitlab import exceptions as exc
3
7
from gitlab import utils
4
- from gitlab .base import RequiredOptional , RESTManager , RESTObject
8
+ from gitlab .base import RequiredOptional , RESTManager , RESTObject , RESTObjectList
5
9
from gitlab .mixins import CRUDMixin , ObjectDeleteMixin , SaveMixin , UserAgentDetailMixin
6
10
7
11
from .award_emojis import ProjectSnippetAwardEmojiManager # noqa: F401
@@ -21,7 +25,13 @@ class Snippet(UserAgentDetailMixin, SaveMixin, ObjectDeleteMixin, RESTObject):
21
25
22
26
@cli .register_custom_action ("Snippet" )
23
27
@exc .on_http_error (exc .GitlabGetError )
24
- def content (self , streamed = False , action = None , chunk_size = 1024 , ** kwargs ):
28
+ def content (
29
+ self ,
30
+ streamed : bool = False ,
31
+ action : Optional [Callable [..., Any ]] = None ,
32
+ chunk_size : int = 1024 ,
33
+ ** kwargs : Any ,
34
+ ) -> Optional [bytes ]:
25
35
"""Return the content of a snippet.
26
36
27
37
Args:
@@ -44,6 +54,8 @@ def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
44
54
result = self .manager .gitlab .http_get (
45
55
path , streamed = streamed , raw = True , ** kwargs
46
56
)
57
+ if TYPE_CHECKING :
58
+ assert isinstance (result , requests .Response )
47
59
return utils .response_content (result , streamed , action , chunk_size )
48
60
49
61
@@ -58,7 +70,7 @@ class SnippetManager(CRUDMixin, RESTManager):
58
70
)
59
71
60
72
@cli .register_custom_action ("SnippetManager" )
61
- def public (self , ** kwargs ) :
73
+ def public (self , ** kwargs : Any ) -> Union [ RESTObjectList , List [ RESTObject ]] :
62
74
"""List all the public snippets.
63
75
64
76
Args:
@@ -73,6 +85,9 @@ def public(self, **kwargs):
73
85
"""
74
86
return self .list (path = "/snippets/public" , ** kwargs )
75
87
88
+ def get (self , id : Union [str , int ], lazy : bool = False , ** kwargs : Any ) -> Snippet :
89
+ return cast (Snippet , super ().get (id = id , lazy = lazy , ** kwargs ))
90
+
76
91
77
92
class ProjectSnippet (UserAgentDetailMixin , SaveMixin , ObjectDeleteMixin , RESTObject ):
78
93
_url = "/projects/{project_id}/snippets"
@@ -84,7 +99,13 @@ class ProjectSnippet(UserAgentDetailMixin, SaveMixin, ObjectDeleteMixin, RESTObj
84
99
85
100
@cli .register_custom_action ("ProjectSnippet" )
86
101
@exc .on_http_error (exc .GitlabGetError )
87
- def content (self , streamed = False , action = None , chunk_size = 1024 , ** kwargs ):
102
+ def content (
103
+ self ,
104
+ streamed : bool = False ,
105
+ action : Optional [Callable [..., Any ]] = None ,
106
+ chunk_size : int = 1024 ,
107
+ ** kwargs : Any ,
108
+ ) -> Optional [bytes ]:
88
109
"""Return the content of a snippet.
89
110
90
111
Args:
@@ -107,6 +128,8 @@ def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
107
128
result = self .manager .gitlab .http_get (
108
129
path , streamed = streamed , raw = True , ** kwargs
109
130
)
131
+ if TYPE_CHECKING :
132
+ assert isinstance (result , requests .Response )
110
133
return utils .response_content (result , streamed , action , chunk_size )
111
134
112
135
@@ -121,3 +144,8 @@ class ProjectSnippetManager(CRUDMixin, RESTManager):
121
144
_update_attrs = RequiredOptional (
122
145
optional = ("title" , "file_name" , "content" , "visibility" , "description" ),
123
146
)
147
+
148
+ def get (
149
+ self , id : Union [str , int ], lazy : bool = False , ** kwargs : Any
150
+ ) -> ProjectSnippet :
151
+ return cast (ProjectSnippet , super ().get (id = id , lazy = lazy , ** kwargs ))
0 commit comments