Skip to content

Commit 13e178a

Browse files
authored
Set line length to 120 characters (#2599)
1 parent de80ff4 commit 13e178a

File tree

192 files changed

+1455
-4433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+1455
-4433
lines changed

.isort.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ multi_line_output=3
33
include_trailing_comma=True
44
force_grid_wrap=0
55
use_parentheses=True
6-
line_length=88
6+
line_length=120
77
known_third_party=dateutil,deprecated,httpretty,jwt,nacl,pytest,requests,setuptools,typing_extensions,urllib3
88
known_first_party=github

doc/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,5 @@
362362
apis.write("\n")
363363
for verb in ["GET", "PATCH", "POST", "PUT", "DELETE"]:
364364
if verb in verbs:
365-
apis.write(
366-
" * " + verb + ": " + " or ".join(sorted(verbs[verb])) + "\n"
367-
)
365+
apis.write(" * " + verb + ": " + " or ".join(sorted(verbs[verb])) + "\n")
368366
apis.write("\n")

github/AccessToken.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def __repr__(self) -> str:
4848
"scope": self.scope,
4949
"type": self.type,
5050
"expires_in": self.expires_in,
51-
"refresh_token": (
52-
f"{self.refresh_token[:5]}..." if self.refresh_token else None
53-
),
51+
"refresh_token": (f"{self.refresh_token[:5]}..." if self.refresh_token else None),
5452
"refresh_token_expires_in": self.refresh_expires_in,
5553
}
5654
)
@@ -137,6 +135,4 @@ def _useAttributes(self, attributes):
137135
if "refresh_token" in attributes: # pragma no branch
138136
self._refresh_token = self._makeStringAttribute(attributes["refresh_token"])
139137
if "refresh_token_expires_in" in attributes: # pragma no branch
140-
self._refresh_expires_in = self._makeIntAttribute(
141-
attributes["refresh_token_expires_in"]
142-
)
138+
self._refresh_expires_in = self._makeIntAttribute(attributes["refresh_token_expires_in"])

github/Artifact.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,18 @@ def delete(self) -> bool:
110110

111111
def _useAttributes(self, attributes):
112112
if "archive_download_url" in attributes: # pragma no branch
113-
self._archive_download_url = self._makeStringAttribute(
114-
attributes["archive_download_url"]
115-
)
113+
self._archive_download_url = self._makeStringAttribute(attributes["archive_download_url"])
116114
if "created_at" in attributes: # pragma no branch
117-
assert attributes["created_at"] is None or isinstance(
118-
attributes["created_at"], (str,)
119-
), attributes["created_at"]
115+
assert attributes["created_at"] is None or isinstance(attributes["created_at"], (str,)), attributes[
116+
"created_at"
117+
]
120118
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
121119
if "expired" in attributes: # pragma no branch
122120
self._expired = self._makeBoolAttribute(attributes["expired"])
123121
if "expires_at" in attributes: # pragma no branch
124-
assert attributes["expires_at"] is None or isinstance(
125-
attributes["expires_at"], (str,)
126-
), attributes["expires_at"]
122+
assert attributes["expires_at"] is None or isinstance(attributes["expires_at"], (str,)), attributes[
123+
"expires_at"
124+
]
127125
self._expires_at = self._makeDatetimeAttribute(attributes["expires_at"])
128126
if "head_sha" in attributes: # pragma no branch
129127
self._head_sha = self._makeStringAttribute(attributes["head_sha"])
@@ -136,13 +134,11 @@ def _useAttributes(self, attributes):
136134
if "size_in_bytes" in attributes: # pragma no branch
137135
self._size_in_bytes = self._makeIntAttribute(attributes["size_in_bytes"])
138136
if "updated_at" in attributes: # pragma no branch
139-
assert attributes["updated_at"] is None or isinstance(
140-
attributes["updated_at"], (str,)
141-
), attributes["updated_at"]
137+
assert attributes["updated_at"] is None or isinstance(attributes["updated_at"], (str,)), attributes[
138+
"updated_at"
139+
]
142140
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
143141
if "url" in attributes: # pragma no branch
144142
self._url = self._makeStringAttribute(attributes["url"])
145143
if "workflow_run" in attributes: # pragma no branch
146-
self._workflow_run = self._makeClassAttribute(
147-
github.WorkflowRun.WorkflowRun, attributes["workflow_run"]
148-
)
144+
self._workflow_run = self._makeClassAttribute(github.WorkflowRun.WorkflowRun, attributes["workflow_run"])

github/Auth.py

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434

3535
# For App authentication, time remaining before token expiration to request a new one
3636
ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDS = 20
37-
TOKEN_REFRESH_THRESHOLD_TIMEDELTA = timedelta(
38-
seconds=ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDS
39-
)
37+
TOKEN_REFRESH_THRESHOLD_TIMEDELTA = timedelta(seconds=ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDS)
4038

4139

4240
class Auth(abc.ABC):
@@ -91,11 +89,7 @@ def token_type(self) -> str:
9189

9290
@property
9391
def token(self) -> str:
94-
return (
95-
base64.b64encode(f"{self.login}:{self.password}".encode())
96-
.decode("utf-8")
97-
.replace("\n", "")
98-
)
92+
return base64.b64encode(f"{self.login}:{self.password}".encode()).decode("utf-8").replace("\n", "")
9993

10094

10195
class Token(Auth):
@@ -192,19 +186,15 @@ def create_jwt(self, expiration=None) -> str:
192186
"""
193187
if expiration is not None:
194188
assert isinstance(expiration, int), expiration
195-
assert (
196-
Consts.MIN_JWT_EXPIRY <= expiration <= Consts.MAX_JWT_EXPIRY
197-
), expiration
189+
assert Consts.MIN_JWT_EXPIRY <= expiration <= Consts.MAX_JWT_EXPIRY, expiration
198190

199191
now = int(time.time())
200192
payload = {
201193
"iat": now + self._jwt_issued_at,
202194
"exp": now + (expiration if expiration is not None else self._jwt_expiry),
203195
"iss": self._app_id,
204196
}
205-
encrypted = jwt.encode(
206-
payload, key=self.private_key, algorithm=self._jwt_algorithm
207-
)
197+
encrypted = jwt.encode(payload, key=self.private_key, algorithm=self._jwt_algorithm)
208198

209199
if isinstance(encrypted, bytes):
210200
return encrypted.decode("utf-8")
@@ -251,9 +241,7 @@ def __init__(
251241

252242
assert isinstance(app_auth, AppAuth), app_auth
253243
assert isinstance(installation_id, int), installation_id
254-
assert token_permissions is None or isinstance(
255-
token_permissions, dict
256-
), token_permissions
244+
assert token_permissions is None or isinstance(token_permissions, dict), token_permissions
257245

258246
self._app_auth = app_auth
259247
self._installation_id = installation_id
@@ -303,16 +291,11 @@ def token(self) -> str:
303291
@property
304292
def _is_expired(self) -> bool:
305293
assert self.__installation_authorization is not None
306-
token_expires_at = (
307-
self.__installation_authorization.expires_at
308-
- TOKEN_REFRESH_THRESHOLD_TIMEDELTA
309-
)
294+
token_expires_at = self.__installation_authorization.expires_at - TOKEN_REFRESH_THRESHOLD_TIMEDELTA
310295
return token_expires_at < datetime.now(timezone.utc)
311296

312297
def _get_installation_authorization(self) -> InstallationAuthorization:
313-
assert (
314-
self.__integration is not None
315-
), "Method withRequester(Requester) must be called first"
298+
assert self.__integration is not None, "Method withRequester(Requester) must be called first"
316299
return self.__integration.get_access_token(
317300
self._installation_id,
318301
permissions=self._token_permissions,
@@ -413,22 +396,13 @@ def withRequester(self, requester: Requester) -> "AppUserAuth":
413396

414397
@property
415398
def _is_expired(self) -> bool:
416-
return self._expires_at is not None and self._expires_at < datetime.now(
417-
timezone.utc
418-
)
399+
return self._expires_at is not None and self._expires_at < datetime.now(timezone.utc)
419400

420401
def _refresh(self):
421402
if self._refresh_token is None:
422-
raise RuntimeError(
423-
"Cannot refresh expired token because no refresh token has been provided"
424-
)
425-
if (
426-
self._refresh_expires_at is not None
427-
and self._refresh_expires_at < datetime.now(timezone.utc)
428-
):
429-
raise RuntimeError(
430-
"Cannot refresh expired token because refresh token also expired"
431-
)
403+
raise RuntimeError("Cannot refresh expired token because no refresh token has been provided")
404+
if self._refresh_expires_at is not None and self._refresh_expires_at < datetime.now(timezone.utc):
405+
raise RuntimeError("Cannot refresh expired token because refresh token also expired")
432406

433407
# refresh token
434408
token = self.__app.refresh_access_token(self._refresh_token)

0 commit comments

Comments
 (0)