@@ -21,15 +21,15 @@ class BaseAuthenticator(ABC):
21
21
"""Provide the base authenticator object that stores OAuth2 credentials."""
22
22
23
23
@abstractmethod
24
- def _auth (self ):
24
+ def _auth (self ) -> tuple [ str , str ] :
25
25
pass
26
26
27
27
def __init__ (
28
28
self ,
29
29
requestor : Requestor ,
30
30
client_id : str ,
31
31
redirect_uri : str | None = None ,
32
- ) -> None :
32
+ ):
33
33
"""Represent a single authentication to Reddit's API.
34
34
35
35
:param requestor: An instance of :class:`.Requestor`.
@@ -60,11 +60,7 @@ def _post(
60
60
return response
61
61
62
62
def authorize_url (
63
- self ,
64
- duration : str ,
65
- scopes : list [str ],
66
- state : str ,
67
- implicit : bool = False ,
63
+ self , duration : str , scopes : list [str ], state : str , implicit : bool = False
68
64
) -> str :
69
65
"""Return the URL used out-of-band to grant access to your application.
70
66
@@ -113,7 +109,7 @@ def authorize_url(
113
109
request = Request ("GET" , url , params = params )
114
110
return request .prepare ().url
115
111
116
- def revoke_token (self , token : str , token_type : str | None = None ) -> None :
112
+ def revoke_token (self , token : str , token_type : str | None = None ):
117
113
"""Ask Reddit to revoke the provided token.
118
114
119
115
:param token: The access or refresh token to revoke.
@@ -134,7 +130,7 @@ class BaseAuthorizer(ABC):
134
130
135
131
AUTHENTICATOR_CLASS : tuple | type = BaseAuthenticator
136
132
137
- def __init__ (self , authenticator : BaseAuthenticator ) -> None :
133
+ def __init__ (self , authenticator : BaseAuthenticator ):
138
134
"""Represent a single authorization to Reddit's API.
139
135
140
136
:param authenticator: An instance of :class:`.BaseAuthenticator`.
@@ -144,12 +140,12 @@ def __init__(self, authenticator: BaseAuthenticator) -> None:
144
140
self ._clear_access_token ()
145
141
self ._validate_authenticator ()
146
142
147
- def _clear_access_token (self ) -> None :
143
+ def _clear_access_token (self ):
148
144
self ._expiration_timestamp : float
149
145
self .access_token : str | None = None
150
146
self .scopes : set [str ] | None = None
151
147
152
- def _request_token (self , ** data : Any ) -> None :
148
+ def _request_token (self , ** data : Any ):
153
149
url = self ._authenticator ._requestor .reddit_url + const .ACCESS_TOKEN_PATH
154
150
pre_request_time = time .time ()
155
151
response = self ._authenticator ._post (url = url , ** data )
@@ -165,7 +161,7 @@ def _request_token(self, **data: Any) -> None:
165
161
self .refresh_token = payload ["refresh_token" ]
166
162
self .scopes = set (payload ["scope" ].split (" " ))
167
163
168
- def _validate_authenticator (self ) -> None :
164
+ def _validate_authenticator (self ):
169
165
if not isinstance (self ._authenticator , self .AUTHENTICATOR_CLASS ):
170
166
msg = "Must use an authenticator of type"
171
167
if isinstance (self .AUTHENTICATOR_CLASS , type ):
@@ -187,7 +183,7 @@ def is_valid(self) -> bool:
187
183
self .access_token is not None and time .time () < self ._expiration_timestamp
188
184
)
189
185
190
- def revoke (self ) -> None :
186
+ def revoke (self ):
191
187
"""Revoke the current Authorization."""
192
188
if self .access_token is None :
193
189
msg = "no token available to revoke"
@@ -208,7 +204,7 @@ def __init__(
208
204
client_id : str ,
209
205
client_secret : str ,
210
206
redirect_uri : str | None = None ,
211
- ) -> None :
207
+ ):
212
208
"""Represent a single authentication to Reddit's API.
213
209
214
210
:param requestor: An instance of :class:`.Requestor`.
@@ -245,7 +241,7 @@ def __init__(
245
241
post_refresh_callback : Callable [[Authorizer ], None ] | None = None ,
246
242
pre_refresh_callback : Callable [[Authorizer ], None ] | None = None ,
247
243
refresh_token : str | None = None ,
248
- ) -> None :
244
+ ):
249
245
"""Represent a single authorization to Reddit's API.
250
246
251
247
:param authenticator: An instance of a subclass of :class:`.BaseAuthenticator`.
@@ -267,7 +263,7 @@ def __init__(
267
263
self ._pre_refresh_callback = pre_refresh_callback
268
264
self .refresh_token = refresh_token
269
265
270
- def authorize (self , code : str ) -> None :
266
+ def authorize (self , code : str ):
271
267
"""Obtain and set authorization tokens based on ``code``.
272
268
273
269
:param code: The code obtained by an out-of-band authorization request to
@@ -283,7 +279,7 @@ def authorize(self, code: str) -> None:
283
279
redirect_uri = self ._authenticator .redirect_uri ,
284
280
)
285
281
286
- def refresh (self ) -> None :
282
+ def refresh (self ):
287
283
"""Obtain a new access token from the refresh_token."""
288
284
if self ._pre_refresh_callback :
289
285
self ._pre_refresh_callback (self )
@@ -296,7 +292,7 @@ def refresh(self) -> None:
296
292
if self ._post_refresh_callback :
297
293
self ._post_refresh_callback (self )
298
294
299
- def revoke (self , only_access : bool = False ) -> None :
295
+ def revoke (self , only_access : bool = False ):
300
296
"""Revoke the current Authorization.
301
297
302
298
:param only_access: When explicitly set to ``True``, do not evict the refresh
@@ -325,7 +321,7 @@ def __init__(
325
321
access_token : str ,
326
322
expires_in : int ,
327
323
scope : str ,
328
- ) -> None :
324
+ ):
329
325
"""Represent a single implicit authorization to Reddit's API.
330
326
331
327
:param authenticator: An instance of :class:`.UntrustedAuthenticator`.
@@ -360,7 +356,7 @@ def __init__(
360
356
self ,
361
357
authenticator : BaseAuthenticator ,
362
358
scopes : list [str ] | None = None ,
363
- ) -> None :
359
+ ):
364
360
"""Represent a ReadOnly authorization to Reddit's API.
365
361
366
362
:param scopes: A list of OAuth scopes to request authorization for (default:
@@ -370,7 +366,7 @@ def __init__(
370
366
super ().__init__ (authenticator )
371
367
self ._scopes = scopes
372
368
373
- def refresh (self ) -> None :
369
+ def refresh (self ):
374
370
"""Obtain a new ReadOnly access token."""
375
371
additional_kwargs = {}
376
372
if self ._scopes :
@@ -395,7 +391,7 @@ def __init__(
395
391
password : str | None ,
396
392
two_factor_callback : Callable | None = None ,
397
393
scopes : list [str ] | None = None ,
398
- ) -> None :
394
+ ):
399
395
"""Represent a single personal-use authorization to Reddit's API.
400
396
401
397
:param authenticator: An instance of :class:`.TrustedAuthenticator`.
@@ -414,7 +410,7 @@ def __init__(
414
410
self ._two_factor_callback = two_factor_callback
415
411
self ._username = username
416
412
417
- def refresh (self ) -> None :
413
+ def refresh (self ):
418
414
"""Obtain a new personal-use script type access token."""
419
415
additional_kwargs = {}
420
416
if self ._scopes :
@@ -445,7 +441,7 @@ def __init__(
445
441
authenticator : BaseAuthenticator ,
446
442
device_id : str | None = None ,
447
443
scopes : list [str ] | None = None ,
448
- ) -> None :
444
+ ):
449
445
"""Represent an app-only OAuth2 authorization for 'installed' apps.
450
446
451
447
:param authenticator: An instance of :class:`.UntrustedAuthenticator` or
@@ -464,7 +460,7 @@ def __init__(
464
460
self ._device_id = device_id
465
461
self ._scopes = scopes
466
462
467
- def refresh (self ) -> None :
463
+ def refresh (self ):
468
464
"""Obtain a new access token."""
469
465
additional_kwargs = {}
470
466
if self ._scopes :
0 commit comments