update code to reflect the new minimum python version 3.7

- update string format method
- remove redundant default arguments from function  calls
- remove unused imports
- remove unicode identifier from strings, it's default in py3 (see: https://stackoverflow.com/a/4182635/12201331)
This commit is contained in:
Peter Pfeufer
2021-10-18 11:59:05 +02:00
parent 2fe1de1c97
commit a6b340c179
199 changed files with 499 additions and 590 deletions

View File

@@ -10,14 +10,14 @@ from .models import EveCorporationInfo
class EveEntityExistsError(forms.ValidationError):
def __init__(self, entity_type_name, id):
super(EveEntityExistsError, self).__init__(
message='{} with ID {} already exists.'.format(entity_type_name, id))
super().__init__(
message=f'{entity_type_name} with ID {id} already exists.')
class EveEntityNotFoundError(forms.ValidationError):
def __init__(self, entity_type_name, id):
super(EveEntityNotFoundError, self).__init__(
message='{} with ID {} not found.'.format(entity_type_name, id))
super().__init__(
message=f'{entity_type_name} with ID {id} not found.')
class EveEntityForm(forms.ModelForm):
@@ -170,4 +170,4 @@ class EveCharacterAdmin(admin.ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
if not obj or not obj.pk:
return EveCharacterForm
return super(EveCharacterAdmin, self).get_form(request, obj=obj, **kwargs)
return super().get_form(request, obj=obj, **kwargs)

View File

@@ -10,7 +10,7 @@ logger = logging.getLogger(__name__)
def sync_user_groups(modeladmin, request, queryset):
for agc in queryset:
logger.debug("update_all_states_group_membership for {}".format(agc))
logger.debug(f"update_all_states_group_membership for {agc}")
agc.update_all_states_group_membership()
@@ -29,7 +29,7 @@ class AutogroupsConfigAdmin(admin.ModelAdmin):
return []
def get_actions(self, request):
actions = super(AutogroupsConfigAdmin, self).get_actions(request)
actions = super().get_actions(request)
actions['sync_user_groups'] = (sync_user_groups,
'sync_user_groups',
'Sync all users groups for this Autogroup Config')

View File

@@ -1,5 +1,4 @@
# Generated by Django 1.11.6 on 2017-12-23 04:30
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion

View File

@@ -26,7 +26,7 @@ class AutogroupsConfigManager(models.Manager):
for config in self.filter(states=state):
logger.debug("in state loop")
for user in users:
logger.debug("in user loop for {}".format(user))
logger.debug(f"in user loop for {user}")
config.update_group_membership_for_user(user)
def update_groups_for_user(self, user: User, state: State = None):
@@ -81,7 +81,7 @@ class AutogroupsConfig(models.Model):
objects = AutogroupsConfigManager()
def __init__(self, *args, **kwargs):
super(AutogroupsConfig, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
def __repr__(self):
return self.__class__.__name__
@@ -111,24 +111,24 @@ class AutogroupsConfig(models.Model):
group = None
try:
if not self.alliance_groups or not self.user_entitled_to_groups(user):
logger.debug('User {} does not have required state for alliance group membership'.format(user))
logger.debug(f'User {user} does not have required state for alliance group membership')
return
else:
alliance = user.profile.main_character.alliance
if alliance is None:
logger.debug('User {} alliance is None, cannot update group membership'.format(user))
logger.debug(f'User {user} alliance is None, cannot update group membership')
return
group = self.get_alliance_group(alliance)
except EveAllianceInfo.DoesNotExist:
logger.debug('User {} main characters alliance does not exist in the database. Creating.'.format(user))
logger.debug(f'User {user} main characters alliance does not exist in the database. Creating.')
alliance = EveAllianceInfo.objects.create_alliance(user.profile.main_character.alliance_id)
group = self.get_alliance_group(alliance)
except AttributeError:
logger.warning('User {} does not have a main character. Group membership not updated'.format(user))
logger.warning(f'User {user} does not have a main character. Group membership not updated')
finally:
self.remove_user_from_alliance_groups(user, except_group=group)
if group is not None:
logger.debug('Adding user {} to alliance group {}'.format(user, group))
logger.debug(f'Adding user {user} to alliance group {group}')
user.groups.add(group)
@transaction.atomic
@@ -136,20 +136,20 @@ class AutogroupsConfig(models.Model):
group = None
try:
if not self.corp_groups or not self.user_entitled_to_groups(user):
logger.debug('User {} does not have required state for corp group membership'.format(user))
logger.debug(f'User {user} does not have required state for corp group membership')
else:
corp = user.profile.main_character.corporation
group = self.get_corp_group(corp)
except EveCorporationInfo.DoesNotExist:
logger.debug('User {} main characters corporation does not exist in the database. Creating.'.format(user))
logger.debug(f'User {user} main characters corporation does not exist in the database. Creating.')
corp = EveCorporationInfo.objects.create_corporation(user.profile.main_character.corporation_id)
group = self.get_corp_group(corp)
except AttributeError:
logger.warning('User {} does not have a main character. Group membership not updated'.format(user))
logger.warning(f'User {user} does not have a main character. Group membership not updated')
finally:
self.remove_user_from_corp_groups(user, except_group=group)
if group is not None:
logger.debug('Adding user {} to corp group {}'.format(user, group))
logger.debug(f'Adding user {user} to corp group {group}')
user.groups.add(group)
@transaction.atomic

View File

@@ -15,7 +15,7 @@ def pre_save_config(sender, instance, *args, **kwargs):
Checks if enable was toggled on group config and
deletes groups if necessary.
"""
logger.debug("Received pre_save from {}".format(instance))
logger.debug(f"Received pre_save from {instance}")
if not instance.pk:
# new model being created
return

View File

@@ -9,7 +9,7 @@ MODULE_PATH = 'allianceauth.eveonline.autogroups'
def patch(target, *args, **kwargs):
return mock.patch('{}{}'.format(MODULE_PATH, target), *args, **kwargs)
return mock.patch(f'{MODULE_PATH}{target}', *args, **kwargs)
def connect_signals():

View File

@@ -56,15 +56,15 @@ def _eve_entity_image_url(
tenants = ['tranquility', 'singularity']
if not entity_id:
raise ValueError('Invalid entity_id: {}'.format(entity_id))
raise ValueError(f'Invalid entity_id: {entity_id}')
else:
entity_id = int(entity_id)
if not size or size < 32 or size > 1024 or (size & (size - 1) != 0):
raise ValueError('Invalid size: {}'.format(size))
raise ValueError(f'Invalid size: {size}')
if category not in categories:
raise ValueError('Invalid category {}'.format(category))
raise ValueError(f'Invalid category {category}')
else:
endpoint = categories[category]['endpoint']
@@ -78,7 +78,7 @@ def _eve_entity_image_url(
variant = categories[category]['variants'][0]
if tenant and tenant not in tenants:
raise ValueError('Invalid tenant {}'.format(tenant))
raise ValueError(f'Invalid tenant {tenant}')
# compose result URL
result = '{}/{}/{}/{}?size={}'.format(
@@ -89,7 +89,7 @@ def _eve_entity_image_url(
size
)
if tenant:
result += '&tenant={}'.format(tenant)
result += f'&tenant={tenant}'
return result

View File

@@ -31,7 +31,7 @@ def _build_url(category: str, eve_id: int) -> str:
url = urljoin(
_BASE_URL,
'{}/{}'.format(partial, int(eve_id))
f'{partial}/{int(eve_id)}'
)
return url

View File

@@ -39,7 +39,7 @@ def _build_url(category: str, eve_id: int) -> str:
url = urljoin(
_BASE_URL,
'{}/{}/'.format(partial, int(eve_id))
f'{partial}/{int(eve_id)}/'
)
return url

View File

@@ -1,5 +1,4 @@
# Generated by Django 1.10.1 on 2016-09-05 21:39
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models

View File

@@ -1,5 +1,4 @@
# Generated by Django 1.10.1 on 2016-09-10 20:20
from __future__ import unicode_literals
from django.db import migrations

View File

@@ -1,5 +1,4 @@
# Generated by Django 1.10.2 on 2016-10-26 01:49
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models

View File

@@ -1,5 +1,4 @@
# Generated by Django 1.10.2 on 2016-11-01 04:20
from __future__ import unicode_literals
from django.db import migrations, models

View File

@@ -1,5 +1,4 @@
# Generated by Django 1.10.1 on 2016-12-16 23:22
from __future__ import unicode_literals
from django.db import migrations

View File

@@ -1,5 +1,4 @@
# Generated by Django 1.10.1 on 2017-01-02 19:23
from __future__ import unicode_literals
from django.db import migrations, models

View File

@@ -1,11 +1,10 @@
# Generated by Django 1.10.5 on 2017-01-18 13:20
from __future__ import unicode_literals
from django.db import migrations, models
def get_duplicates(items):
return set([item for item in items if items.count(item) > 1])
return {item for item in items if items.count(item) > 1}
def enforce_unique_characters(apps, schema_editor):

View File

@@ -1,5 +1,4 @@
# Generated by Django 1.10.5 on 2017-03-22 23:09
from __future__ import unicode_literals
from django.db import migrations

View File

@@ -1,5 +1,4 @@
# Generated by Django 1.11.5 on 2017-09-28 02:16
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion

View File

@@ -34,10 +34,10 @@ class ObjectNotFound(Exception):
self.type = type_name
def __str__(self):
return '%s with ID %s not found.' % (self.type, self.id)
return f'{self.type} with ID {self.id} not found.'
class Entity(object):
class Entity:
def __init__(self, id=None, name=None):
self.id = id
self.name = name
@@ -46,7 +46,7 @@ class Entity(object):
return self.name
def __repr__(self):
return "<{} ({}): {}>".format(self.__class__.__name__, self.id, self.name)
return f"<{self.__class__.__name__} ({self.id}): {self.name}>"
def __bool__(self):
return bool(self.id)
@@ -57,7 +57,7 @@ class Entity(object):
class Corporation(Entity):
def __init__(self, ticker=None, ceo_id=None, members=None, alliance_id=None, **kwargs):
super(Corporation, self).__init__(**kwargs)
super().__init__(**kwargs)
self.ticker = ticker
self.ceo_id = ceo_id
self.members = members
@@ -82,7 +82,7 @@ class Corporation(Entity):
class Alliance(Entity):
def __init__(self, ticker=None, corp_ids=None, executor_corp_id=None, **kwargs):
super(Alliance, self).__init__(**kwargs)
super().__init__(**kwargs)
self.ticker = ticker
self.corp_ids = corp_ids
self.executor_corp_id = executor_corp_id
@@ -97,7 +97,7 @@ class Alliance(Entity):
@property
def corps(self):
return sorted([self.corp(c_id) for c_id in self.corp_ids], key=lambda x: x.name)
return sorted((self.corp(c_id) for c_id in self.corp_ids), key=lambda x: x.name)
@property
def executor_corp(self):
@@ -108,7 +108,7 @@ class Alliance(Entity):
class Character(Entity):
def __init__(self, corp_id=None, alliance_id=None, **kwargs):
super(Character, self).__init__(**kwargs)
super().__init__(**kwargs)
self.corp_id = corp_id
self.alliance_id = alliance_id
self._corp = None
@@ -129,10 +129,10 @@ class Character(Entity):
class ItemType(Entity):
def __init__(self, **kwargs):
super(ItemType, self).__init__(**kwargs)
super().__init__(**kwargs)
class EveProvider(object):
class EveProvider:
def get_alliance(self, alliance_id):
"""
:return: an Alliance object for the given ID

View File

@@ -18,7 +18,7 @@ def set_logger(logger_name: str, name: str) -> object:
'%(asctime)s - %(levelname)s - %(module)s:%(funcName)s - %(message)s'
)
f_handler = logging.FileHandler(
'{}.log'.format(os.path.splitext(name)[0]),
f'{os.path.splitext(name)[0]}.log',
'w+'
)
f_handler.setFormatter(f_format)