Skip to content

Commit 7f39e59

Browse files
Merge pull request #844 from SUNET/ylle-more-ruf-rules
Enable RUF010 and RUF015 ruff rules
2 parents 7d84dff + b724f5c commit 7f39e59

Some content is hidden

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

73 files changed

+139
-147
lines changed

ruff.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ ignore = [
3232
"SIM102", # collapsible-if
3333
"SIM103", # return-bool-condition-directly (keeping explicit if/else for clarity)
3434
"SIM108", # if-else-block-instead-of-if-exp
35-
"RUF010", # use conversion flag instead
3635
"RUF012", # mutable class attributes
37-
"RUF015", # single element slices
3836

3937
# Since we use ruff as a formatter, the following rules should be ignored
4038
# See: https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules

src/eduid/common/rpc/am_relay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ def ping(self, timeout: int = 1) -> str:
7777
return rtask.get(timeout=timeout)
7878
except Exception as e:
7979
rtask.forget()
80-
raise AmTaskFailed(f"ping task failed: {repr(e)}") from e
80+
raise AmTaskFailed(f"ping task failed: {e!r}") from e

src/eduid/common/rpc/lookup_mobile_relay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ def ping(self, timeout: int = 1) -> str:
4646
return rtask.get(timeout=timeout)
4747
except Exception as e:
4848
rtask.forget()
49-
raise LookupMobileTaskFailed(f"ping task failed: {repr(e)}") from e
49+
raise LookupMobileTaskFailed(f"ping task failed: {e!r}") from e

src/eduid/common/rpc/msg_relay.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def sendsms(self, recipient: str, message: str, reference: str, timeout: int = 2
267267
logger.info(f"SMS with reference {reference} sent. Task result: {res}")
268268
except Exception as e:
269269
rtask.forget()
270-
raise MsgTaskFailed(f"sendsms task failed: {repr(e)}") from e
270+
raise MsgTaskFailed(f"sendsms task failed: {e!r}") from e
271271

272272
def ping(self, timeout: int = 1) -> str:
273273
"""
@@ -279,4 +279,4 @@ def ping(self, timeout: int = 1) -> str:
279279
return rtask.get(timeout=timeout)
280280
except Exception as e:
281281
rtask.forget()
282-
raise MsgTaskFailed(f"ping task failed: {repr(e)}") from e
282+
raise MsgTaskFailed(f"ping task failed: {e!r}") from e

src/eduid/graphdb/groupdb/db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ def get_group(self, identifier: str) -> Group | None:
246246
group_data: Node | None # please mypy
247247
if len(group_graph.relationships) == 0:
248248
# Just a group with no owners or members
249-
group_data = [node_data for node_data in group_graph.nodes][0]
249+
group_data = next(iter(group_graph.nodes))
250250
assert group_data is not None
251251
return self._load_group(group_data)
252252
else:
253253
# Grab the first relationships end node and create the group from that
254-
group_data = [node_data.end_node for node_data in group_graph.relationships][0]
254+
group_data = next(iter(group_graph.relationships)).end_node
255255
assert group_data is not None
256256
group = self._load_group(group_data)
257257

src/eduid/maccapi/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -
8888
)
8989

9090
if not data_owner or data_owner not in self.context.config.data_owners:
91-
self.context.logger.error(f"Data owner {repr(data_owner)} not configured")
91+
self.context.logger.error(f"Data owner {data_owner!r} not configured")
9292
return return_error_response(status_code=status.HTTP_401_UNAUTHORIZED, detail="Unknown data_owner")
9393

9494
assert isinstance(request.context, MaccAPIContext) # please mypy

src/eduid/maccapi/tests/test_maccapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def setUp(self) -> None:
2626

2727
def _make_bearer_token(self, claims: Mapping[str, Any]) -> str:
2828
token = jwt.JWT(header={"alg": "ES256"}, claims=claims)
29-
jwk = list(self.context.jwks)[0]
29+
jwk = next(iter(self.context.jwks))
3030
token.make_signed_token(jwk)
3131
return token.serialize()
3232

src/eduid/queue/workers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async def process_new_item(self, document_id: str) -> None:
109109
try:
110110
await self.handle_new_item(queue_item)
111111
except Exception as e:
112-
logger.exception(f"QueueItem processing failed with: {repr(e)}")
112+
logger.exception(f"QueueItem processing failed with: {e!r}")
113113

114114
async def handle_change(self, change: ChangeEvent) -> None:
115115
"""

src/eduid/satosa/scimapi/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ def get_metadata(context: satosa.context.Context) -> Generator[MetaData]:
4040

4141
def get_internal_attribute_name(converter: AttributeMapper, attr_name: str) -> str:
4242
_int = converter.to_internal("saml", {attr_name: ["something"]})
43-
return list(_int.keys())[0]
43+
return next(iter(_int.keys()))

src/eduid/satosa/scimapi/scim_attributes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(
5959
# Get the internal attribute name for the eduPersonPrincipalName that will be
6060
# used to find users in the SCIM database
6161
_int = self.converter.to_internal("saml", {"eduPersonPrincipalName": "something"})
62-
self.ext_id_attr = list(_int.keys())[0]
62+
self.ext_id_attr = next(iter(_int.keys()))
6363
logger.debug(f"SCIM externalId internal attribute name: {self.ext_id_attr}")
6464

6565
def get_userdb_for_data_owner(self, data_owner: str) -> ScimApiUserDB:
@@ -155,7 +155,7 @@ def _process_user(self, user: ScimApiUser, data: satosa.internal.InternalData) -
155155
for _name, _new in update.items():
156156
_old = data.attributes.get(_name)
157157
if _old != _new:
158-
logger.debug(f"Changing attribute {_name} from {repr(_old)} to {repr(_new)}")
158+
logger.debug(f"Changing attribute {_name} from {_old!r} to {_new!r}")
159159
data.attributes[_name] = _new
160160

161161
# Look for a linked account suitable for use for MFA stepup (in the stepup plugin that runs after this one)

0 commit comments

Comments
 (0)