@@ -60,8 +60,13 @@ class GitHub(models.GitHubCore):
60
60
"""
61
61
62
62
def __init__ (
63
- self , username = "" , password = "" , token = "" , session = None , api_version = ""
64
- ):
63
+ self ,
64
+ username : str = "" ,
65
+ password : str = "" ,
66
+ token : str = "" ,
67
+ session : t .Optional [session .GitHubSession ] = None ,
68
+ api_version : str = "" ,
69
+ ) -> None :
65
70
"""Create a new GitHub instance to talk to the API.
66
71
67
72
:param str api_version:
@@ -79,13 +84,15 @@ def __init__(
79
84
elif username and password :
80
85
self .login (username , password )
81
86
82
- def _repr (self ):
87
+ def _repr (self ) -> str :
83
88
if self .session .auth :
84
89
return f"<GitHub [{ self .session .auth !r} ]>"
85
90
return f"<Anonymous GitHub at 0x{ id (self ):x} >"
86
91
87
92
@requires_auth
88
- def activate_membership (self , organization ):
93
+ def activate_membership (
94
+ self , organization : t .Union [str , orgs .Organization ]
95
+ ) -> t .Optional [orgs .Membership ]:
89
96
"""Activate the membership to an organization.
90
97
91
98
:param organization:
@@ -109,7 +116,9 @@ def activate_membership(self, organization):
109
116
return self ._instance_or_null (orgs .Membership , _json )
110
117
111
118
@requires_auth
112
- def add_email_addresses (self , addresses = []):
119
+ def add_email_addresses (
120
+ self , addresses : t .Optional [t .List [str ]] = None
121
+ ) -> t .Sequence [users .Email ]:
113
122
"""Add the addresses to the authenticated user's account.
114
123
115
124
:param list addresses:
@@ -123,9 +132,15 @@ def add_email_addresses(self, addresses=[]):
123
132
if addresses :
124
133
url = self ._build_url ("user" , "emails" )
125
134
json = self ._json (self ._post (url , data = addresses ), 201 )
126
- return [users .Email (email , self ) for email in json ] if json else []
135
+ return (
136
+ [users .Email (email , self .session ) for email in json ]
137
+ if json
138
+ else []
139
+ )
127
140
128
- def all_events (self , number = - 1 , etag = None ):
141
+ def all_events (
142
+ self , number : int = - 1 , etag : t .Optional [str ] = None
143
+ ) -> t .Iterable [events .Event ]:
129
144
"""Iterate over public events.
130
145
131
146
:param int number:
@@ -142,8 +157,12 @@ def all_events(self, number=-1, etag=None):
142
157
return self ._iter (int (number ), url , events .Event , etag = etag )
143
158
144
159
def all_organizations (
145
- self , number = - 1 , since = None , etag = None , per_page = None
146
- ):
160
+ self ,
161
+ number : int = - 1 ,
162
+ since : t .Optional [int ] = None ,
163
+ etag : t .Optional [str ] = None ,
164
+ per_page : t .Optional [int ] = None ,
165
+ ) -> t .Iterable [orgs .ShortOrganization ]:
147
166
"""Iterate over every organization in the order they were created.
148
167
149
168
:param int number:
@@ -171,8 +190,12 @@ def all_organizations(
171
190
)
172
191
173
192
def all_repositories (
174
- self , number = - 1 , since = None , etag = None , per_page = None
175
- ):
193
+ self ,
194
+ number : int = - 1 ,
195
+ since : t .Optional [int ] = None ,
196
+ etag : t .Optional [str ] = None ,
197
+ per_page : t .Optional [int ] = None ,
198
+ ) -> t .Iterable [repo .Repository ]:
176
199
"""Iterate over every repository in the order they were created.
177
200
178
201
:param int number:
@@ -199,7 +222,13 @@ def all_repositories(
199
222
etag = etag ,
200
223
)
201
224
202
- def all_users (self , number = - 1 , etag = None , per_page = None , since = None ):
225
+ def all_users (
226
+ self ,
227
+ number : int = - 1 ,
228
+ etag : t .Optional [str ] = None ,
229
+ per_page : t .Optional [int ] = None ,
230
+ since : t .Optional [int ] = None ,
231
+ ) -> t .Iterable [users .ShortUser ]:
203
232
"""Iterate over every user in the order they signed up for GitHub.
204
233
205
234
.. versionchanged:: 1.0.0
@@ -229,7 +258,7 @@ def all_users(self, number=-1, etag=None, per_page=None, since=None):
229
258
params = {"per_page" : per_page , "since" : since },
230
259
)
231
260
232
- def app (self , app_slug ) :
261
+ def app (self , app_slug : t . Any ) -> t . Optional [ apps . App ] :
233
262
"""Retrieve information about a specific app using its "slug".
234
263
235
264
.. versionadded:: 1.2.0
@@ -256,7 +285,9 @@ def app(self, app_slug):
256
285
return self ._instance_or_null (apps .App , json )
257
286
258
287
@decorators .requires_app_bearer_auth
259
- def app_installation (self , installation_id ):
288
+ def app_installation (
289
+ self , installation_id : int
290
+ ) -> t .Optional [apps .Installation ]:
260
291
"""Retrieve a specific App installation by its ID.
261
292
262
293
.. versionadded: 1.2.0
@@ -283,7 +314,9 @@ def app_installation(self, installation_id):
283
314
return self ._instance_or_null (apps .Installation , json )
284
315
285
316
@decorators .requires_app_bearer_auth
286
- def app_installations (self , number = - 1 ):
317
+ def app_installations (
318
+ self , number : int = - 1
319
+ ) -> t .Iterable [apps .Installation ]:
287
320
"""Retrieve the list of installations for the authenticated app.
288
321
289
322
.. versionadded:: 1.2.0
@@ -310,7 +343,9 @@ def app_installations(self, number=-1):
310
343
)
311
344
312
345
@decorators .requires_app_bearer_auth
313
- def app_installation_for_organization (self , organization ):
346
+ def app_installation_for_organization (
347
+ self , organization : str
348
+ ) -> t .Iterable [apps .Installation ]:
314
349
"""Retrieve an App installation for a specific organization.
315
350
316
351
.. versionadded:: 1.2.0
@@ -337,7 +372,9 @@ def app_installation_for_organization(self, organization):
337
372
return self ._instance_or_null (apps .Installation , json )
338
373
339
374
@decorators .requires_app_bearer_auth
340
- def app_installation_for_repository (self , owner , repository ):
375
+ def app_installation_for_repository (
376
+ self , owner : str , repository : str
377
+ ) -> t .Optional [apps .Installation ]:
341
378
"""Retrieve an App installation for a specific repository.
342
379
343
380
.. versionadded:: 1.2.0
@@ -1283,7 +1320,7 @@ def issues_on(
1283
1320
assignee = None ,
1284
1321
mentioned = None ,
1285
1322
labels = None ,
1286
- sort = None ,
1323
+ sort : str | None = None ,
1287
1324
direction = None ,
1288
1325
since = None ,
1289
1326
number = - 1 ,
@@ -2037,13 +2074,13 @@ def repositories(
2037
2074
2038
2075
def repositories_by (
2039
2076
self ,
2040
- username ,
2041
- type = None ,
2042
- sort = None ,
2043
- direction = None ,
2044
- number = - 1 ,
2045
- etag = None ,
2046
- ):
2077
+ username : str ,
2078
+ type : t . Optional [ str ] = None ,
2079
+ sort : t . Optional [ str ] = None ,
2080
+ direction : t . Optional [ str ] = None ,
2081
+ number : int = - 1 ,
2082
+ etag : t . Optional [ str ] = None ,
2083
+ ) -> t . Iterable [ repo . ShortRepository ] :
2047
2084
"""List public repositories for the specified ``username``.
2048
2085
2049
2086
.. versionadded:: 0.6
@@ -2073,7 +2110,7 @@ def repositories_by(
2073
2110
"""
2074
2111
url = self ._build_url ("users" , username , "repos" )
2075
2112
2076
- params = {}
2113
+ params : t . MutableMapping [ str , t . Union [ int , str , None ]] = {}
2077
2114
if type in ("all" , "owner" , "member" ):
2078
2115
params .update (type = type )
2079
2116
if sort in ("created" , "updated" , "pushed" , "full_name" ):
@@ -2085,7 +2122,9 @@ def repositories_by(
2085
2122
int (number ), url , repo .ShortRepository , params , etag
2086
2123
)
2087
2124
2088
- def repository (self , owner , repository ):
2125
+ def repository (
2126
+ self , owner : str , repository : str
2127
+ ) -> t .Optional [repo .Repository ]:
2089
2128
"""Retrieve the desired repository.
2090
2129
2091
2130
:param str owner:
@@ -2104,7 +2143,9 @@ def repository(self, owner, repository):
2104
2143
return self ._instance_or_null (repo .Repository , json )
2105
2144
2106
2145
@requires_auth
2107
- def repository_invitations (self , number = - 1 , etag = None ):
2146
+ def repository_invitations (
2147
+ self , number : int = - 1 , etag : t .Optional [str ] = None
2148
+ ) -> t .Iterator [invitation .Invitation ]:
2108
2149
"""Iterate over the repository invitations for the current user.
2109
2150
2110
2151
:param int number:
0 commit comments