1+ from typing import Any ,Callable ,cast ,List ,Optional ,TYPE_CHECKING ,Union
2+
3+ import requests
4+
15from gitlab import cli
26from gitlab import exceptions as exc
37from gitlab import utils
4- from gitlab .base import RequiredOptional ,RESTManager ,RESTObject
8+ from gitlab .base import RequiredOptional ,RESTManager ,RESTObject , RESTObjectList
59from gitlab .mixins import CRUDMixin ,ObjectDeleteMixin ,SaveMixin ,UserAgentDetailMixin
610
711from .award_emojis import ProjectSnippetAwardEmojiManager # 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- 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 ]:
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):
4454result = self .manager .gitlab .http_get (
4555path ,streamed = streamed ,raw = True ,** kwargs
4656 )
57+ if TYPE_CHECKING :
58+ assert isinstance (result ,requests .Response )
4759return utils .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- def public (self ,** kwargs ) :
73+ def public (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 """
7486return self .list (path = "/snippets/public" ,** kwargs )
7587
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+
7691
7792class ProjectSnippet (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- 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 ]:
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):
107128result = self .manager .gitlab .http_get (
108129path ,streamed = streamed ,raw = True ,** kwargs
109130 )
131+ if TYPE_CHECKING :
132+ assert isinstance (result ,requests .Response )
110133return utils .response_content (result ,streamed ,action ,chunk_size )
111134
112135
@@ -121,3 +144,8 @@ class ProjectSnippetManager(CRUDMixin, RESTManager):
121144_update_attrs = RequiredOptional (
122145optional = ("title" ,"file_name" ,"content" ,"visibility" ,"description" ),
123146 )
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 ))