Skip to content

Commit

Permalink
re-add list comprehension rule and patches
Browse files Browse the repository at this point in the history
  • Loading branch information
helylle committed Sep 18, 2024
1 parent 90ffa40 commit 597119a
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 35 deletions.
3 changes: 1 addition & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ select = ["E", "F", "W", "I", "ASYNC", "UP", "FLY", "PERF", "FURB"]

# For now, ignore E501 (line too long) errors. They are in strings and comments.
# For now, ignore PERF203 (try-except-in-loop), TODO: fix them.
# For now, ignore PERF401 (manual-list-comprehension), TODO: fix them.
ignore = ["E501", "PERF203", "PERF401"]
ignore = ["E501", "PERF203"]
12 changes: 8 additions & 4 deletions src/eduid/graphdb/groupdb/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,10 @@ def get_groups_by_property(self, key: str, value: str, skip=0, limit=100):
RETURN g as group SKIP $skip LIMIT $limit
"""
with self.db.driver.session(default_access_mode=READ_ACCESS) as session:
for record in session.run(q, scope=self.scope, value=value, skip=skip, limit=limit):
res.append(self._load_group(record.data()["group"]))
res = [
self._load_group(record.data()["group"])
for record in session.run(q, scope=self.scope, value=value, skip=skip, limit=limit)
]
return res

def get_groups(self, skip: int = 0, limit: int = 100) -> list[Group]:
Expand All @@ -295,8 +297,10 @@ def get_groups(self, skip: int = 0, limit: int = 100) -> list[Group]:
RETURN g as group SKIP $skip LIMIT $limit
"""
with self.db.driver.session(default_access_mode=READ_ACCESS) as session:
for record in session.run(q, scope=self.scope, skip=skip, limit=limit):
res.append(self._load_group(record.data()["group"]))
res = [
self._load_group(record.data()["group"])
for record in session.run(q, scope=self.scope, skip=skip, limit=limit)
]
return res

def _get_groups_for_role(self, label: Label, identifier: str, role: Role):
Expand Down
9 changes: 3 additions & 6 deletions src/eduid/scimapi/routers/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
@groups_router.get("/", response_model=ListResponse)
async def on_get_all(req: ContextRequest) -> ListResponse:
db_groups = req.context.groupdb.get_groups()
resources = []
for db_group in db_groups:
resources.append({"id": str(db_group.scim_id), "displayName": db_group.graph.display_name})
resources = [{"id": str(db_group.scim_id), "displayName": db_group.graph.display_name} for db_group in db_groups]
return ListResponse(total_results=len(db_groups), resources=resources)


Expand Down Expand Up @@ -302,7 +300,6 @@ async def search(req: ContextRequest, query: SearchRequest) -> ListResponse:
else:
raise BadRequest(scim_type="invalidFilter", detail=f"Can't filter on attribute {_filter.attr}")

resources = []
for this in groups:
resources.append({"id": str(this.scim_id), "displayName": this.display_name})
resources = [{"id": str(this.scim_id), "displayName": this.display_name} for this in groups]

return ListResponse(total_results=total_count, resources=resources)
9 changes: 4 additions & 5 deletions src/eduid/scimapi/test-scripts/scim-util.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,10 @@ def put_group(api: Api, scim_id: str, data: dict[str, Any], token: str | None =
if display_name:
scim["displayName"] = display_name
if members:
new_members = []
for member in members:
new_members.append(
{"$ref": f'{api}/Users/{member["id"]}', "value": member["id"], "display": member["display_name"]}
)
new_members = [
{"$ref": f'{api}/Users/{member["id"]}', "value": member["id"], "display": member["display_name"]}
for member in members
]
scim["members"] = new_members
if "data" in data:
if NUTID_GROUP_V1 not in scim["schemas"]:
Expand Down
11 changes: 5 additions & 6 deletions src/eduid/userdb/group_management/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ def get_states_by_email_addresses(self, email_addresses: list[str]) -> list[Grou
:raise self.DocumentDoesNotExist: No document match the search criteria
"""
states: list[GroupInviteState] = []
for email_address in email_addresses:
spec = {"email_address": email_address}
for this in self._get_documents_by_filter(spec):
states.append(GroupInviteState.from_dict(this))

states: list[GroupInviteState] = [
GroupInviteState.from_dict(state)
for email_address in email_addresses
for state in self._get_documents_by_filter({"email_address": email_address})
]
return states

def save(self, state: GroupInviteState, is_in_database: bool) -> SaveResult:
Expand Down
4 changes: 1 addition & 3 deletions src/eduid/webapp/common/api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def get_marked_given_name(given_name: str, given_name_marking: str | None) -> st
else:
_given_names.append(name)

_optional_marked_names: list[str | None] = []
for i in given_name_marking:
_optional_marked_names.append(_given_names[int(i)])
_optional_marked_names: list[str | None] = [_given_names[int(i)] for i in given_name_marking]
# remove None values
# i.e. 0 index and hyphenated names second part placeholder
_marked_names: list[str] = [name for name in _optional_marked_names if name is not None]
Expand Down
3 changes: 1 addition & 2 deletions src/eduid/webapp/common/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ def get_zxcvbn_terms(user: User) -> list[str]:

# Mail addresses
if user.mail_addresses.count:
for item in user.mail_addresses.to_list():
user_input.append(item.email.split("@")[0])
user_input.extend(item.email.split("@")[0] for item in user.mail_addresses.to_list())

return user_input

Expand Down
7 changes: 3 additions & 4 deletions src/eduid/webapp/security/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,9 @@ def get_approved_security_keys() -> dict[str, Any]:
)
parsed_entries.append(authenticator_info)

approved_keys_list: list[str] = []
for entry in parsed_entries:
if entry.description and is_authenticator_mfa_approved(entry):
approved_keys_list.append(entry.description)
approved_keys_list: list[str] = [
entry.description for entry in parsed_entries if entry.description and is_authenticator_mfa_approved(entry)
]

# remove case-insensitive duplicates from list, while maintaining the original case
marker = set()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ def _search_by_SSNo(self, national_identity_number: str) -> list[str]:
if record is None:
return []

mobile_numbers = []
for r in record:
mobile_numbers.append(r.Mobiles)
mobile_numbers = [r.Mobiles for r in record]

return mobile_numbers

Expand Down

0 comments on commit 597119a

Please sign in to comment.