From ab25da0aa1bfe6aeed3872a590e88109fcd208e6 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 7 Aug 2024 13:46:39 -0400 Subject: [PATCH] Apply Ruff's flake8-builtins (A) rules --- doorcontrol/hid/Credential.py | 10 +++++----- doorcontrol/models.py | 6 +++--- doorcontrol/tasks/update_doors.py | 4 ++-- membershipworks/models.py | 4 ++-- membershipworks/tasks/scrape.py | 4 ++-- paperwork/api.py | 2 +- pyproject.toml | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/doorcontrol/hid/Credential.py b/doorcontrol/hid/Credential.py index 90ab8f0..25ab94c 100644 --- a/doorcontrol/hid/Credential.py +++ b/doorcontrol/hid/Credential.py @@ -5,10 +5,10 @@ import bitstring class Credential: - def __init__(self, code=None, hex=None): - if code is None and hex is None: + def __init__(self, code=None, hex_code=None): + if code is None and hex_code is None: raise TypeError("Must set either code or hex for a Credential") - elif code is not None and hex is not None: + elif code is not None and hex_code is not None: raise TypeError("Cannot set both code and hex for a Credential") elif code is not None: self.bits = bitstring.pack( @@ -18,8 +18,8 @@ class Credential: ) self.bits[6] = self.bits[7:19].count(1) % 2 # even parity self.bits[31] = not (self.bits[19:31].count(1) % 2) # odd parity - elif hex is not None: - self.bits = bitstring.Bits(hex=hex) + elif hex_code is not None: + self.bits = bitstring.Bits(hex=hex_code) def __repr__(self): return f"Credential({self.code})" diff --git a/doorcontrol/models.py b/doorcontrol/models.py index ab71498..41fe89e 100644 --- a/doorcontrol/models.py +++ b/doorcontrol/models.py @@ -242,11 +242,11 @@ class HIDEvent(models.Model): field.column: field.attname for field in HIDEvent._meta.get_fields() } - def attr_to_bool(str): - if str is None: + def attr_to_bool(attr): + if attr is None: return None else: - return str == "true" + return attr == "true" return cls( **{ diff --git a/doorcontrol/tasks/update_doors.py b/doorcontrol/tasks/update_doors.py index 097a67b..3cdc18c 100644 --- a/doorcontrol/tasks/update_doors.py +++ b/doorcontrol/tasks/update_doors.py @@ -108,7 +108,7 @@ class DoorMember: }, cardholderID=data.attrib["cardholderID"], credentials={ - Credential(hex=(c.attrib["rawCardNumber"])) + Credential(hex_code=(c.attrib["rawCardNumber"])) for c in data.findall("{*}Credential") }, schedules={r.attrib["scheduleName"] for r in data.findall("{*}Role")}, @@ -222,7 +222,7 @@ def update_door(door: Door, dry_run: bool = False): } existing_door_credentials = { - Credential(hex=c.attrib["rawCardNumber"]) + Credential(hex_code=c.attrib["rawCardNumber"]) for c in door.controller.get_credentials() } diff --git a/membershipworks/models.py b/membershipworks/models.py index 2e84aab..59f216a 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -381,8 +381,8 @@ class EventCategory(models.Model): return self.title @classmethod - def from_api_dict(cls, id: int, data): - return cls(id=id, title=data["ttl"]) + def from_api_dict(cls, id_: int, data): + return cls(id=id_, title=data["ttl"]) class Event(BaseModel): diff --git a/membershipworks/tasks/scrape.py b/membershipworks/tasks/scrape.py index ada35e3..3fa72d5 100644 --- a/membershipworks/tasks/scrape.py +++ b/membershipworks/tasks/scrape.py @@ -33,8 +33,8 @@ def flags_for_member(csv_member, all_flags, folders): def update_flags(mw_flags) -> Iterable[Flag]: for typ, flags_of_type in mw_flags.items(): - for name, id in flags_of_type.items(): - flag = Flag(id=id, name=name, type=typ[:-1]) + for name, flag_id in flags_of_type.items(): + flag = Flag(id=flag_id, name=name, type=typ[:-1]) flag.save() yield flag diff --git a/paperwork/api.py b/paperwork/api.py index b55350e..64140e2 100644 --- a/paperwork/api.py +++ b/paperwork/api.py @@ -39,7 +39,7 @@ class DepartmentViewSet(viewsets.ModelViewSet): serializer_class = DepartmentSerializer @action(detail=False, methods=["get"]) - def mailing_lists(self, request, format=None): + def mailing_lists(self, request, format=None): # noqa: A002 """ Generate a mailing list for each department, containing all certified users for tools in that department or child departments diff --git a/pyproject.toml b/pyproject.toml index aaa19a8..8373c44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,7 +60,7 @@ admin_email = "cmsmanage.django_q2_admin_email_reporter:AdminEmailReporter" line-length = 88 [tool.ruff.lint] -select = ["E4", "E7", "E9", "F", "I", "C4", "UP", "PERF", "PL", "SIM", "FIX003", "DJ012"] +select = ["E4", "E7", "E9", "F", "I", "C4", "UP", "PERF", "PL", "SIM", "FIX003", "DJ012", "A"] [tool.ruff.lint.isort] known-first-party = [