From 20fcac99a846bc436b2ab2e3cfbbd29be740a4e0 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 7 Aug 2024 14:29:52 -0400 Subject: [PATCH] Apply Ruff's flake8-bugbear (B) rules --- doorcontrol/hid/DoorController.py | 4 ++-- doorcontrol/hid/tests/test_DoorController.py | 2 +- doorcontrol/tasks/update_doors.py | 4 ++-- membershipworks/models.py | 2 +- membershipworks/tasks/scrape.py | 4 +++- pyproject.toml | 1 + 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/doorcontrol/hid/DoorController.py b/doorcontrol/hid/DoorController.py index da4421d..d40738c 100644 --- a/doorcontrol/hid/DoorController.py +++ b/doorcontrol/hid/DoorController.py @@ -152,7 +152,7 @@ class DoorController: ) return self.doXMLRequest(el) - def get_records(self, req, count, params={}, stopFunction=None): + def get_records(self, req, count, params=None, stopFunction=None): recordCount = 0 moreRecords = True @@ -172,7 +172,7 @@ class DoorController: "recordOffset": str( recordCount - 1 if recordCount > 0 else 0 ), - **params, + **(params or {}), } ) ) diff --git a/doorcontrol/hid/tests/test_DoorController.py b/doorcontrol/hid/tests/test_DoorController.py index 8059780..c7aa6b9 100644 --- a/doorcontrol/hid/tests/test_DoorController.py +++ b/doorcontrol/hid/tests/test_DoorController.py @@ -15,7 +15,7 @@ def assert_elements_equal(e1: Element, e2: Element) -> None: assert e1.attrib == e2.attrib assert len(e1) == len(e2) - for c1, c2 in zip(e1, e2): + for c1, c2 in zip(e1, e2, strict=True): assert_elements_equal(c1, c2) diff --git a/doorcontrol/tasks/update_doors.py b/doorcontrol/tasks/update_doors.py index 3cdc18c..3c155d0 100644 --- a/doorcontrol/tasks/update_doors.py +++ b/doorcontrol/tasks/update_doors.py @@ -136,7 +136,7 @@ class DoorMember: self, existing_door_credentials: set[Credential], all_members: list["DoorMember"], - old_credentials: set[Credential] = set(), + old_credentials: set[Credential], ): # cardholderID should be set on a member before this is called assert self.cardholderID is not None @@ -240,7 +240,7 @@ def update_door(door: Door, dry_run: bool = False): ] member.update_attribs() - member.update_credentials(existing_door_credentials, members) + member.update_credentials(existing_door_credentials, members, set()) member.update_schedules() # cardholder exists, compare contents diff --git a/membershipworks/models.py b/membershipworks/models.py index 0e8b456..80941fc 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -590,7 +590,7 @@ class EventExt(Event): self.materials_fee_included_in_price is not None or self.materials_fee == 0 ) - and getattr(self, "total_due_to_instructor") is not None + and self.total_due_to_instructor is not None ) diff --git a/membershipworks/tasks/scrape.py b/membershipworks/tasks/scrape.py index 3fa72d5..f08505f 100644 --- a/membershipworks/tasks/scrape.py +++ b/membershipworks/tasks/scrape.py @@ -81,7 +81,9 @@ def scrape_transactions(membershipworks: MembershipWorks): transactions_csv = membershipworks.get_transactions(start_date, now) transactions_json = membershipworks.get_transactions(start_date, now, json=True) # this is terrible, but as long as the dates are the same, should be fiiiine - transactions = [{**j, **v} for j, v in zip(transactions_csv, transactions_json)] + transactions = [ + {**j, **v} for j, v in zip(transactions_csv, transactions_json, strict=True) + ] assert all( t["Account ID"] == t.get("uid", "") and t["Payment ID"] == t.get("sid", "") for t in transactions diff --git a/pyproject.toml b/pyproject.toml index 23efa8b..662c5af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -83,6 +83,7 @@ select = [ "TCH", "PTH", "FURB", + "B", ] ignore = ["ISC001"]