Skip to content

Commit 6105f7e

Browse files
committed
Code clean up
1 parent 3a0b5ea commit 6105f7e

16 files changed

+84
-132
lines changed

.flake8

-2
This file was deleted.

.github/ISSUE_TEMPLATE/bug_report.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ body:
2828
- id: credential-check
2929
attributes:
3030
description: |
31-
The `Reddit()` initialization in my code example does not include the following parameters to prevent credential leakage:
31+
The `Reddit()` initialization in my code example does not include the following parameters to prevent credential leakage:
3232
`client_secret`, `password`, or `refresh_token`.
3333
label: My code does not include sensitive credentials
3434
options:
@@ -77,7 +77,7 @@ body:
7777
- id: prawcore-version
7878
attributes:
7979
description: What version of `prawcore` are you encountering this issue with? Obtain this by running `pip show prawcore`.
80-
label: "`prawcore` Version"
80+
label: prawcore Version
8181
type: input
8282
validations:
8383
required: true

AUTHORS.rst

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
prawcore is written and maintained by Bryce Boe and various contributors:
2-
31
Maintainers
42
===========
53

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ https://github.com/praw-dev/prawcore/tree/main/examples
8888
Depending on prawcore
8989
---------------------
9090

91-
prawcore follows `semantic versioning <http://semver.org/>`_ with the exception that
91+
prawcore follows `semantic versioning <https://semver.org/>`_ with the exception that
9292
deprecations will not be preceded by a minor release. In essence, expect only major
9393
versions to introduce breaking changes to prawcore's public interface. As a result, if
9494
you depend on prawcore then it is a good idea to specify not only the minimum version of

prawcore/auth.py

+21-25
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class BaseAuthenticator(ABC):
2121
"""Provide the base authenticator object that stores OAuth2 credentials."""
2222

2323
@abstractmethod
24-
def _auth(self):
24+
def _auth(self) -> tuple[str, str]:
2525
pass
2626

2727
def __init__(
2828
self,
2929
requestor: Requestor,
3030
client_id: str,
3131
redirect_uri: str | None = None,
32-
) -> None:
32+
):
3333
"""Represent a single authentication to Reddit's API.
3434
3535
:param requestor: An instance of :class:`.Requestor`.
@@ -60,11 +60,7 @@ def _post(
6060
return response
6161

6262
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
6864
) -> str:
6965
"""Return the URL used out-of-band to grant access to your application.
7066
@@ -113,7 +109,7 @@ def authorize_url(
113109
request = Request("GET", url, params=params)
114110
return request.prepare().url
115111

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):
117113
"""Ask Reddit to revoke the provided token.
118114
119115
:param token: The access or refresh token to revoke.
@@ -134,7 +130,7 @@ class BaseAuthorizer(ABC):
134130

135131
AUTHENTICATOR_CLASS: tuple | type = BaseAuthenticator
136132

137-
def __init__(self, authenticator: BaseAuthenticator) -> None:
133+
def __init__(self, authenticator: BaseAuthenticator):
138134
"""Represent a single authorization to Reddit's API.
139135
140136
:param authenticator: An instance of :class:`.BaseAuthenticator`.
@@ -144,12 +140,12 @@ def __init__(self, authenticator: BaseAuthenticator) -> None:
144140
self._clear_access_token()
145141
self._validate_authenticator()
146142

147-
def _clear_access_token(self) -> None:
143+
def _clear_access_token(self):
148144
self._expiration_timestamp: float
149145
self.access_token: str | None = None
150146
self.scopes: set[str] | None = None
151147

152-
def _request_token(self, **data: Any) -> None:
148+
def _request_token(self, **data: Any):
153149
url = self._authenticator._requestor.reddit_url + const.ACCESS_TOKEN_PATH
154150
pre_request_time = time.time()
155151
response = self._authenticator._post(url=url, **data)
@@ -165,7 +161,7 @@ def _request_token(self, **data: Any) -> None:
165161
self.refresh_token = payload["refresh_token"]
166162
self.scopes = set(payload["scope"].split(" "))
167163

168-
def _validate_authenticator(self) -> None:
164+
def _validate_authenticator(self):
169165
if not isinstance(self._authenticator, self.AUTHENTICATOR_CLASS):
170166
msg = "Must use an authenticator of type"
171167
if isinstance(self.AUTHENTICATOR_CLASS, type):
@@ -187,7 +183,7 @@ def is_valid(self) -> bool:
187183
self.access_token is not None and time.time() < self._expiration_timestamp
188184
)
189185

190-
def revoke(self) -> None:
186+
def revoke(self):
191187
"""Revoke the current Authorization."""
192188
if self.access_token is None:
193189
msg = "no token available to revoke"
@@ -208,7 +204,7 @@ def __init__(
208204
client_id: str,
209205
client_secret: str,
210206
redirect_uri: str | None = None,
211-
) -> None:
207+
):
212208
"""Represent a single authentication to Reddit's API.
213209
214210
:param requestor: An instance of :class:`.Requestor`.
@@ -245,7 +241,7 @@ def __init__(
245241
post_refresh_callback: Callable[[Authorizer], None] | None = None,
246242
pre_refresh_callback: Callable[[Authorizer], None] | None = None,
247243
refresh_token: str | None = None,
248-
) -> None:
244+
):
249245
"""Represent a single authorization to Reddit's API.
250246
251247
:param authenticator: An instance of a subclass of :class:`.BaseAuthenticator`.
@@ -267,7 +263,7 @@ def __init__(
267263
self._pre_refresh_callback = pre_refresh_callback
268264
self.refresh_token = refresh_token
269265

270-
def authorize(self, code: str) -> None:
266+
def authorize(self, code: str):
271267
"""Obtain and set authorization tokens based on ``code``.
272268
273269
:param code: The code obtained by an out-of-band authorization request to
@@ -283,7 +279,7 @@ def authorize(self, code: str) -> None:
283279
redirect_uri=self._authenticator.redirect_uri,
284280
)
285281

286-
def refresh(self) -> None:
282+
def refresh(self):
287283
"""Obtain a new access token from the refresh_token."""
288284
if self._pre_refresh_callback:
289285
self._pre_refresh_callback(self)
@@ -296,7 +292,7 @@ def refresh(self) -> None:
296292
if self._post_refresh_callback:
297293
self._post_refresh_callback(self)
298294

299-
def revoke(self, only_access: bool = False) -> None:
295+
def revoke(self, only_access: bool = False):
300296
"""Revoke the current Authorization.
301297
302298
:param only_access: When explicitly set to ``True``, do not evict the refresh
@@ -325,7 +321,7 @@ def __init__(
325321
access_token: str,
326322
expires_in: int,
327323
scope: str,
328-
) -> None:
324+
):
329325
"""Represent a single implicit authorization to Reddit's API.
330326
331327
:param authenticator: An instance of :class:`.UntrustedAuthenticator`.
@@ -360,7 +356,7 @@ def __init__(
360356
self,
361357
authenticator: BaseAuthenticator,
362358
scopes: list[str] | None = None,
363-
) -> None:
359+
):
364360
"""Represent a ReadOnly authorization to Reddit's API.
365361
366362
:param scopes: A list of OAuth scopes to request authorization for (default:
@@ -370,7 +366,7 @@ def __init__(
370366
super().__init__(authenticator)
371367
self._scopes = scopes
372368

373-
def refresh(self) -> None:
369+
def refresh(self):
374370
"""Obtain a new ReadOnly access token."""
375371
additional_kwargs = {}
376372
if self._scopes:
@@ -395,7 +391,7 @@ def __init__(
395391
password: str | None,
396392
two_factor_callback: Callable | None = None,
397393
scopes: list[str] | None = None,
398-
) -> None:
394+
):
399395
"""Represent a single personal-use authorization to Reddit's API.
400396
401397
:param authenticator: An instance of :class:`.TrustedAuthenticator`.
@@ -414,7 +410,7 @@ def __init__(
414410
self._two_factor_callback = two_factor_callback
415411
self._username = username
416412

417-
def refresh(self) -> None:
413+
def refresh(self):
418414
"""Obtain a new personal-use script type access token."""
419415
additional_kwargs = {}
420416
if self._scopes:
@@ -445,7 +441,7 @@ def __init__(
445441
authenticator: BaseAuthenticator,
446442
device_id: str | None = None,
447443
scopes: list[str] | None = None,
448-
) -> None:
444+
):
449445
"""Represent an app-only OAuth2 authorization for 'installed' apps.
450446
451447
:param authenticator: An instance of :class:`.UntrustedAuthenticator` or
@@ -464,7 +460,7 @@ def __init__(
464460
self._device_id = device_id
465461
self._scopes = scopes
466462

467-
def refresh(self) -> None:
463+
def refresh(self):
468464
"""Obtain a new access token."""
469465
additional_kwargs = {}
470466
if self._scopes:

prawcore/exceptions.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ class InvalidInvocation(PrawcoreException):
1919
class OAuthException(PrawcoreException):
2020
"""Indicate that there was an OAuth2 related error with the request."""
2121

22-
def __init__(
23-
self, response: Response, error: str, description: str | None = None
24-
) -> None:
22+
def __init__(self, response: Response, error: str, description: str | None = None):
2523
"""Initialize a OAuthException instance.
2624
2725
:param response: A ``requests.response`` instance.
@@ -48,7 +46,7 @@ def __init__(
4846
request_kwargs: dict[
4947
str, bool | (dict[str, int] | (dict[str, str] | str)) | None
5048
],
51-
) -> None:
49+
):
5250
"""Initialize a RequestException instance.
5351
5452
:param original_exception: The original exception that occurred.
@@ -65,7 +63,7 @@ def __init__(
6563
class ResponseException(PrawcoreException):
6664
"""Indicate that there was an error with the completed HTTP request."""
6765

68-
def __init__(self, response: Response) -> None:
66+
def __init__(self, response: Response):
6967
"""Initialize a ResponseException instance.
7068
7169
:param response: A ``requests.response`` instance.
@@ -111,7 +109,7 @@ class Redirect(ResponseException):
111109
112110
"""
113111

114-
def __init__(self, response: Response) -> None:
112+
def __init__(self, response: Response):
115113
"""Initialize a Redirect exception instance.
116114
117115
:param response: A ``requests.response`` instance containing a location header.
@@ -137,7 +135,7 @@ class ServerError(ResponseException):
137135
class SpecialError(ResponseException):
138136
"""Indicate syntax or spam-prevention issues."""
139137

140-
def __init__(self, response: Response) -> None:
138+
def __init__(self, response: Response):
141139
"""Initialize a SpecialError exception instance.
142140
143141
:param response: A ``requests.response`` instance containing a message and a
@@ -160,7 +158,7 @@ class TooLarge(ResponseException):
160158
class TooManyRequests(ResponseException):
161159
"""Indicate that the user has sent too many requests in a given amount of time."""
162160

163-
def __init__(self, response: Response) -> None:
161+
def __init__(self, response: Response):
164162
"""Initialize a TooManyRequests exception instance.
165163
166164
:param response: A ``requests.response`` instance that may contain a retry-after

prawcore/rate_limit.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RateLimiter:
1818
1919
"""
2020

21-
def __init__(self, *, window_size: int) -> None:
21+
def __init__(self, *, window_size: int):
2222
"""Create an instance of the RateLimit class."""
2323
self.remaining: float | None = None
2424
self.next_request_timestamp: float | None = None
@@ -48,7 +48,7 @@ def call(
4848
self.update(response.headers)
4949
return response
5050

51-
def delay(self) -> None:
51+
def delay(self):
5252
"""Sleep for an amount of time to remain under the rate limit."""
5353
if self.next_request_timestamp is None:
5454
return
@@ -59,7 +59,7 @@ def delay(self) -> None:
5959
log.debug(message)
6060
time.sleep(sleep_seconds)
6161

62-
def update(self, response_headers: Mapping[str, str]) -> None:
62+
def update(self, response_headers: Mapping[str, str]):
6363
"""Update the state of the rate limiter based on the response headers.
6464
6565
This method should only be called following an HTTP request to Reddit.

prawcore/requestor.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
from .exceptions import InvalidInvocation, RequestException
1010

1111
if TYPE_CHECKING:
12-
from requests.models import Response
13-
14-
from .sessions import Session
12+
from requests.models import Response, Session
1513

1614

1715
class Requestor:
@@ -30,7 +28,7 @@ def __init__(
3028
reddit_url: str = "https://www.reddit.com",
3129
session: Session | None = None,
3230
timeout: float = TIMEOUT,
33-
) -> None:
31+
):
3432
"""Create an instance of the Requestor class.
3533
3634
:param user_agent: The user-agent for your application. Please follow Reddit's
@@ -39,7 +37,7 @@ def __init__(
3937
(default: ``"https://oauth.reddit.com"``).
4038
:param reddit_url: The URL used when obtaining access tokens (default:
4139
``"https://www.reddit.com"``).
42-
:param session: A session to handle requests, compatible with
40+
:param session: A session instance to handle requests, compatible with
4341
``requests.Session()`` (default: ``None``).
4442
:param timeout: How many seconds to wait for the server to send data before
4543
giving up (default: ``prawcore.const.TIMEOUT``).
@@ -59,9 +57,9 @@ def __init__(
5957
self.reddit_url = reddit_url
6058
self.timeout = timeout
6159

62-
def close(self) -> None:
60+
def close(self):
6361
"""Call close on the underlying session."""
64-
return self._http.close()
62+
self._http.close()
6563

6664
def request(
6765
self, *args: Any, timeout: float | None = None, **kwargs: Any

0 commit comments

Comments
 (0)