From 4561e317b84aec3ce702a03b6e92ed980d9e3b08 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 19 Jan 2024 15:16:47 -0500 Subject: [PATCH] Enable/apply ruff's "flake6-simplify" rules --- doorcontrol/hid/DoorController.py | 8 +++----- membershipworks/membershipworks_api.py | 7 +++---- membershipworks/tasks/scrape.py | 4 +--- pyproject.toml | 2 +- rentals/views.py | 7 ++----- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/doorcontrol/hid/DoorController.py b/doorcontrol/hid/DoorController.py index b51b21a..da4421d 100644 --- a/doorcontrol/hid/DoorController.py +++ b/doorcontrol/hid/DoorController.py @@ -1,3 +1,4 @@ +import contextlib import csv from datetime import datetime from io import StringIO @@ -120,11 +121,8 @@ class DoorController: for ii in range(1, 8) ] ) - try: - self.doXMLRequest(delXML) - except RemoteError: - # don't care about failure to delete, they probably just didn't exist - pass + # don't care about failure to delete, they probably just didn't exist + contextlib.suppress(self.doXMLRequest(delXML)) # load new schedules self.doXMLRequest(schedules) diff --git a/membershipworks/membershipworks_api.py b/membershipworks/membershipworks_api.py index 5dfa673..aa1f550 100644 --- a/membershipworks/membershipworks_api.py +++ b/membershipworks/membershipworks_api.py @@ -138,9 +138,8 @@ class MembershipWorks: for element in box["box"]: if not isinstance(element["dat"], str): for field in element["dat"]: - if "_id" in field: - if field["_id"] not in fields: - fields[field["_id"]] = field + if "_id" in field and field["_id"] not in fields: + fields[field["_id"]] = field return fields @@ -218,7 +217,7 @@ class MembershipWorks: r = self._get_v1( BASE_URL + "/v1/csv", params={ - "crm": ",".join(str(k) for k in CRM.keys()), + "crm": ",".join(str(k) for k in CRM), **({"txl": ""} if json else {}), "sdp": start_date.strftime("%s"), "edp": end_date.strftime("%s"), diff --git a/membershipworks/tasks/scrape.py b/membershipworks/tasks/scrape.py index dd101c8..065b59f 100644 --- a/membershipworks/tasks/scrape.py +++ b/membershipworks/tasks/scrape.py @@ -55,9 +55,7 @@ def scrape_members(membershipworks: MembershipWorks): field.get("typ") == FieldType.CHECKBOX.value and field["lbl"] in csv_member ): - csv_member[field["lbl"]] = ( - True if csv_member[field["lbl"]] == "Y" else False - ) + csv_member[field["lbl"]] = csv_member[field["lbl"]] == "Y" # create/update member member = Member.from_api_dict(csv_member) diff --git a/pyproject.toml b/pyproject.toml index 7878065..22c5e93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ admin_email = "cmsmanage.django_q2_admin_email_reporter:AdminEmailReporter" [tool.ruff] line-length = 88 -select = ["E4", "E7", "E9", "F", "I", "C4", "UP", "PERF", "PL"] +select = ["E4", "E7", "E9", "F", "I", "C4", "UP", "PERF", "PL", "SIM"] [tool.ruff.lint.isort] known-first-party = [ diff --git a/rentals/views.py b/rentals/views.py index 91bfa7d..2861496 100644 --- a/rentals/views.py +++ b/rentals/views.py @@ -1,7 +1,7 @@ from django.contrib import messages from django.contrib.auth.decorators import login_required, permission_required from django.http import HttpResponseRedirect -from django.shortcuts import render +from django.shortcuts import get_object_or_404, render from django.urls import reverse from .forms import LockerInfoForm @@ -31,10 +31,7 @@ def lockerIndex(request): @permission_required("rentals.change_lockerinfo", raise_exception=True) def lockerUpdate(request, locker_id: int): if request.method == "POST": - try: - instance = LockerInfo.objects.get(pk=locker_id) - except LockerInfo.DoesNotExist: - pass # TODO + instance = get_object_or_404(LockerInfo, pk=locker_id) form = LockerInfoForm(request.POST, instance=instance) if form.is_valid():