Skip to content

Commit 35365e1

Browse files
authored
Enable ruff flake8-return (RET) rule and apply fixes (#43)
1 parent e036125 commit 35365e1

File tree

6 files changed

+16
-21
lines changed

6 files changed

+16
-21
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ line-length = 88
4848
target-version = "py311"
4949

5050
[tool.ruff.lint]
51-
select = ["E4", "E7", "E9", "F", "UP", "S", "ANN", "C4", "I", "RUF", "SIM", "PLR", "ERA"]
51+
select = ["E4", "E7", "E9", "F", "UP", "S", "ANN", "C4", "I", "RUF", "SIM", "PLR", "ERA", "RET"]
5252
# select = ["ALL"]
5353
ignore = ["ANN003", "ANN401", "D", "COM"]
5454

src/pythonxbox/api/provider/ratelimitedprovider.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,11 @@ def __parse_rate_limit_key(
6969
if isinstance(key, int) and not isinstance(key, bool):
7070
# bool is a subclass of int, hence the explicit check
7171
return ParsedRateLimit(read=key, write=key, period=period)
72-
elif isinstance(key, dict):
72+
if isinstance(key, dict):
7373
# TODO: schema here?
7474
# Since the key-value pairs match we can just pass the dict to the model
7575
return ParsedRateLimit(**key, period=period)
7676

77-
else:
78-
raise XboxException(
79-
"RATE_LIMITS value types not recognised. Must be one of 'int, 'dict'."
80-
)
77+
raise XboxException(
78+
"RATE_LIMITS value types not recognised. Must be one of 'int, 'dict'."
79+
)

src/pythonxbox/authentication/xal.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ def _generate_code_verifier() -> str:
112112
def _get_code_challenge_from_code_verifier(code_verifier: str) -> str:
113113
code_challenge = hashlib.sha256(code_verifier.encode()).digest()
114114
# Base64 urlsafe encoding WITH stripping trailing '='
115-
code_challenge = base64.urlsafe_b64encode(code_challenge).decode().rstrip("=")
116-
117-
return code_challenge
115+
return base64.urlsafe_b64encode(code_challenge).decode().rstrip("=")
118116

119117
@staticmethod
120118
def _generate_random_state() -> str:
@@ -345,8 +343,6 @@ async def auth_flow(
345343
)
346344

347345
# Do Sisu authorization
348-
sisu_authorization = await self.do_sisu_authorization(
346+
return await self.do_sisu_authorization(
349347
sisu_session_id, tokens.access_token, device_token_resp.token
350348
)
351-
352-
return sisu_authorization

src/pythonxbox/common/filetimes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,4 @@ def filetime_to_dt(ft: int) -> datetime:
7777
# Convert to datetime object
7878
dt = datetime.fromtimestamp(s, UTC)
7979
# Add remainder in as microseconds. Python 3.2 requires an integer
80-
dt = dt.replace(microsecond=(ns100 // 10))
81-
return dt
80+
return dt.replace(microsecond=(ns100 // 10))

src/pythonxbox/common/request_signer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,13 @@ def _concat_data_to_sign( # noqa: PLR0913
179179

180180
@staticmethod
181181
def __base64_escaped(binary: bytes) -> str:
182-
encoded = base64.b64encode(binary).decode("ascii")
183-
encoded = encoded.rstrip("=")
184-
encoded = encoded.replace("+", "-")
185-
encoded = encoded.replace("/", "_")
186-
return encoded
182+
return (
183+
base64.b64encode(binary)
184+
.decode("ascii")
185+
.rstrip("=")
186+
.replace("+", "-")
187+
.replace("/", "_")
188+
)
187189

188190
@staticmethod
189191
def __encode_ec_coord(coord: int) -> str:

src/pythonxbox/scripts/xal.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@ def user_prompt_authentication(auth_url: str) -> str:
4242
Takes the redirect URL from stdin
4343
"""
4444

45-
redirect_url = input(
45+
return input(
4646
f"Continue auth with the following URL:\n\n"
4747
f"URL: {auth_url}\n\n"
4848
f"Provide redirect URI: "
4949
)
50-
return redirect_url
5150

5251

5352
async def do_auth(device_id: uuid.UUID, token_filepath: str) -> None:

0 commit comments

Comments
 (0)