From 75d67aa1b194fa1eba04cfc5af3d2594541e3bbd Mon Sep 17 00:00:00 2001 From: Joel Falknau Date: Wed, 26 Mar 2025 13:18:54 +1000 Subject: [PATCH] typehints --- .pre-commit-config.yaml | 6 +++--- allianceauth/authentication/models.py | 6 +++--- allianceauth/corputils/models.py | 4 ++-- allianceauth/eveonline/autogroups/models.py | 4 ++-- allianceauth/eveonline/models.py | 8 ++++---- allianceauth/eveonline/providers.py | 6 +++--- allianceauth/eveonline/tests/esi_client_stub.py | 2 +- allianceauth/fleetactivitytracking/models.py | 4 ++-- allianceauth/groupmanagement/models.py | 6 +++--- allianceauth/hrapplications/models.py | 12 ++++++------ allianceauth/optimer/models.py | 4 ++-- allianceauth/services/modules/discourse/models.py | 2 +- allianceauth/srp/models.py | 4 ++-- 13 files changed, 34 insertions(+), 34 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0404b9a2..50f65283 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ exclude: | repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.9.9 + rev: v0.11.0 hooks: # Run the linter, and only the linter - id: ruff @@ -59,7 +59,7 @@ repos: - id: detect-private-key - id: check-case-conflict # Python checks -# - id: check-docstring-first +# - id: debug-statements # - id: requirements-txt-fixer - id: fix-encoding-pragma @@ -97,6 +97,6 @@ repos: hooks: - id: tox-ini-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.23 + rev: v0.24 hooks: - id: validate-pyproject diff --git a/allianceauth/authentication/models.py b/allianceauth/authentication/models.py index e1fb30e9..7828cc92 100644 --- a/allianceauth/authentication/models.py +++ b/allianceauth/authentication/models.py @@ -32,7 +32,7 @@ class State(models.Model): class Meta: ordering = ['-priority'] - def __str__(self): + def __str__(self) -> str: return self.name def available_to_character(self, character): @@ -153,7 +153,7 @@ class CharacterOwnership(models.Model): class Meta: default_permissions = ('change', 'delete') ordering = ['user', 'character__character_name'] - def __str__(self): + def __str__(self) -> str: return f"{self.user}: {self.character}" @@ -166,5 +166,5 @@ class OwnershipRecord(models.Model): class Meta: ordering = ['-created'] - def __str__(self): + def __str__(self) -> str: return f"{self.user}: {self.character} on {self.created}" diff --git a/allianceauth/corputils/models.py b/allianceauth/corputils/models.py index a98ec5cb..2f91a104 100644 --- a/allianceauth/corputils/models.py +++ b/allianceauth/corputils/models.py @@ -45,7 +45,7 @@ class CorpStats(models.Model): - def __str__(self): + def __str__(self) -> str: return f"{self.__class__.__name__} for {self.corp}" def update(self): @@ -154,7 +154,7 @@ class CorpMember(models.Model): unique_together = ('corpstats', 'character_id') ordering = ['character_name'] - def __str__(self): + def __str__(self) -> str: return self.character_name @property diff --git a/allianceauth/eveonline/autogroups/models.py b/allianceauth/eveonline/autogroups/models.py index 3f28f313..315403d4 100644 --- a/allianceauth/eveonline/autogroups/models.py +++ b/allianceauth/eveonline/autogroups/models.py @@ -81,7 +81,7 @@ class AutogroupsConfig(models.Model): objects = AutogroupsConfigManager() - def __str__(self): + def __str__(self) -> str: return 'States: ' + (' '.join(list(self.states.all().values_list('name', flat=True))) if self.pk else str(None)) def __init__(self, *args, **kwargs): @@ -235,7 +235,7 @@ class ManagedGroup(models.Model): class Meta: abstract = True - def __str__(self): + def __str__(self) -> str: return f"Managed Group: {self.group.name}" class ManagedCorpGroup(ManagedGroup): diff --git a/allianceauth/eveonline/models.py b/allianceauth/eveonline/models.py index 6c9e621d..2b863ba5 100644 --- a/allianceauth/eveonline/models.py +++ b/allianceauth/eveonline/models.py @@ -32,7 +32,7 @@ class EveFactionInfo(models.Model): provider = providers.provider - def __str__(self): + def __str__(self) -> str: return self.faction_name @staticmethod @@ -80,7 +80,7 @@ class EveAllianceInfo(models.Model): class Meta: indexes = [models.Index(fields=['executor_corp_id',])] - def __str__(self): + def __str__(self) -> str: return self.alliance_name def populate_alliance(self): alliance = self.provider.get_alliance(self.alliance_id) @@ -152,7 +152,7 @@ class EveCorporationInfo(models.Model): class Meta: indexes = [models.Index(fields=['ceo_id',]),] - def __str__(self): + def __str__(self) -> str: return self.corporation_name def update_corporation(self, corp: providers.Corporation = None): if corp is None: @@ -226,7 +226,7 @@ class EveCharacter(models.Model): models.Index(fields=['faction_id',]), ] - def __str__(self): + def __str__(self) -> str: return self.character_name @property diff --git a/allianceauth/eveonline/providers.py b/allianceauth/eveonline/providers.py index 69203aaa..0d231ead 100644 --- a/allianceauth/eveonline/providers.py +++ b/allianceauth/eveonline/providers.py @@ -36,7 +36,7 @@ class ObjectNotFound(Exception): self.id = obj_id self.type = type_name - def __str__(self): + def __str__(self) -> str: return f'{self.type} with ID {self.id} not found.' @@ -46,7 +46,7 @@ class Entity: self.id = id self.name = name - def __str__(self): + def __str__(self) -> str: return self.name def __repr__(self): @@ -206,7 +206,7 @@ class EveSwaggerProvider(EveProvider): ) return self._client - def __str__(self): + def __str__(self) -> str: return 'esi' def get_alliance(self, alliance_id: int) -> Alliance: diff --git a/allianceauth/eveonline/tests/esi_client_stub.py b/allianceauth/eveonline/tests/esi_client_stub.py index 6b7c3ee1..3e8c69be 100644 --- a/allianceauth/eveonline/tests/esi_client_stub.py +++ b/allianceauth/eveonline/tests/esi_client_stub.py @@ -13,7 +13,7 @@ class BravadoResponseStub: self.headers = headers if headers else {} self.raw_bytes = raw_bytes - def __str__(self): + def __str__(self) -> str: return f"{self.status_code} {self.reason}" diff --git a/allianceauth/fleetactivitytracking/models.py b/allianceauth/fleetactivitytracking/models.py index b4041efc..a250fc68 100644 --- a/allianceauth/fleetactivitytracking/models.py +++ b/allianceauth/fleetactivitytracking/models.py @@ -13,7 +13,7 @@ class Fatlink(models.Model): hash = models.CharField(max_length=254, unique=True) creator = models.ForeignKey(User, on_delete=models.SET(get_sentinel_user)) - def __str__(self): + def __str__(self) -> str: return self.fleet @@ -28,5 +28,5 @@ class Fat(models.Model): class Meta: unique_together = (('character', 'fatlink'),) - def __str__(self): + def __str__(self) -> str: return f"Fat-link for {self.character.character_name}" diff --git a/allianceauth/groupmanagement/models.py b/allianceauth/groupmanagement/models.py index 39e93d32..70f5380f 100644 --- a/allianceauth/groupmanagement/models.py +++ b/allianceauth/groupmanagement/models.py @@ -15,7 +15,7 @@ class GroupRequest(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) group = models.ForeignKey(Group, on_delete=models.CASCADE) - def __str__(self): + def __str__(self) -> str: return self.user.username + ":" + self.group.name @property @@ -50,7 +50,7 @@ class RequestLog(models.Model): request_actor = models.ForeignKey(User, on_delete=models.CASCADE) date = models.DateTimeField(auto_now_add=True) - def __str__(self): + def __str__(self) -> str: return self.pk def requestor(self): @@ -179,7 +179,7 @@ class AuthGroup(models.Model): ) default_permissions = () - def __str__(self): + def __str__(self) -> str: return self.group.name def group_request_approvers(self) -> set[User]: diff --git a/allianceauth/hrapplications/models.py b/allianceauth/hrapplications/models.py index 2b3414d6..7cabf086 100644 --- a/allianceauth/hrapplications/models.py +++ b/allianceauth/hrapplications/models.py @@ -13,7 +13,7 @@ class ApplicationQuestion(models.Model): help_text = models.CharField(max_length=254, blank=True) multi_select = models.BooleanField(default=False) - def __str__(self): + def __str__(self) -> str: return "Question: " + self.title @@ -21,7 +21,7 @@ class ApplicationChoice(models.Model): question = models.ForeignKey(ApplicationQuestion,on_delete=models.CASCADE,related_name="choices") choice_text = models.CharField(max_length=200, verbose_name='Choice') - def __str__(self): + def __str__(self) -> str: return self.choice_text @@ -29,7 +29,7 @@ class ApplicationForm(models.Model): questions = SortedManyToManyField(ApplicationQuestion) corp = models.OneToOneField(EveCorporationInfo, on_delete=models.CASCADE) - def __str__(self): + def __str__(self) -> str: return str(self.corp) @@ -50,7 +50,7 @@ class Application(models.Model): ('view_apis', 'Can view applicant APIs'),) unique_together = ('form', 'user') - def __str__(self): + def __str__(self) -> str: return str(self.user) + " Application To " + str(self.form) @property @@ -77,7 +77,7 @@ class ApplicationResponse(models.Model): answer = models.TextField() class Meta: unique_together = ('question', 'application') - def __str__(self): + def __str__(self) -> str: return str(self.application) + " Answer To " + str(self.question) @@ -89,5 +89,5 @@ class ApplicationComment(models.Model): text = models.TextField() created = models.DateTimeField(auto_now_add=True) - def __str__(self): + def __str__(self) -> str: return str(self.user) + " comment on " + str(self.application) diff --git a/allianceauth/optimer/models.py b/allianceauth/optimer/models.py index daa7a80e..6c044eae 100644 --- a/allianceauth/optimer/models.py +++ b/allianceauth/optimer/models.py @@ -19,7 +19,7 @@ class OpTimerType(models.Model): ordering = ['type'] default_permissions = () - def __str__(self): + def __str__(self) -> str: return self.type class OpTimer(models.Model): @@ -39,5 +39,5 @@ class OpTimer(models.Model): class Meta: ordering = ['start'] default_permissions = () - def __str__(self): + def __str__(self) -> str: return self.operation_name diff --git a/allianceauth/services/modules/discourse/models.py b/allianceauth/services/modules/discourse/models.py index 8f121c81..395d6931 100644 --- a/allianceauth/services/modules/discourse/models.py +++ b/allianceauth/services/modules/discourse/models.py @@ -16,5 +16,5 @@ class DiscourseUser(models.Model): ("access_discourse", "Can access the Discourse service"), ) - def __str__(self): + def __str__(self) -> str: return self.user.username diff --git a/allianceauth/srp/models.py b/allianceauth/srp/models.py index 58369e89..78e3c384 100644 --- a/allianceauth/srp/models.py +++ b/allianceauth/srp/models.py @@ -18,7 +18,7 @@ class SrpFleetMain(models.Model): class Meta: permissions = (('access_srp', 'Can access SRP module'),) - def __str__(self): + def __str__(self) -> str: return self.fleet_name @property @@ -46,5 +46,5 @@ class SrpUserRequest(models.Model): srp_ship_name = models.CharField(max_length=254, default="") post_time = models.DateTimeField(default=timezone.now) - def __str__(self): + def __str__(self) -> str: return self.character.character_name + ' SRP request for ' + self.srp_ship_name