From 4d53038426aedf2abf337a2876d0d6ceccefc09b Mon Sep 17 00:00:00 2001 From: Paul Traylor Date: Mon, 13 Jun 2022 14:29:17 +0900 Subject: [PATCH 1/2] pyupgrade --py36-plus promgen/**/*.py --- promgen/admin.py | 2 +- promgen/celery.py | 3 +- promgen/checks.py | 4 +- promgen/discovery/__init__.py | 2 +- promgen/forms.py | 4 +- promgen/management/commands/alerts-index.py | 2 +- promgen/management/commands/import-jobs.py | 4 +- .../management/commands/register-exporter.py | 4 +- .../management/commands/register-server.py | 6 +-- promgen/middleware.py | 2 +- .../0001_squashed_0044_common-rules.py | 10 ++--- promgen/migrations/0002_auto_20180316_0525.py | 2 - promgen/models.py | 34 ++++++++--------- promgen/notification/__init__.py | 2 +- promgen/notification/user.py | 15 ++++---- promgen/prometheus.py | 2 +- promgen/proxy.py | 5 +-- promgen/signals.py | 14 +++---- promgen/templatetags/promgen.py | 2 +- promgen/tests/test_alert_rules.py | 2 +- promgen/tests/test_signals.py | 2 +- promgen/util.py | 2 +- promgen/views.py | 38 +++++++++---------- 23 files changed, 77 insertions(+), 86 deletions(-) diff --git a/promgen/admin.py b/promgen/admin.py index 54e86aef4..f18a5cc57 100644 --- a/promgen/admin.py +++ b/promgen/admin.py @@ -120,7 +120,7 @@ class RuleAdmin(admin.ModelAdmin): inlines = [RuleLabelInline, RuleAnnotationInline] def get_queryset(self, request): - qs = super(RuleAdmin, self).get_queryset(request) + qs = super().get_queryset(request) return qs.prefetch_related('content_object',) diff --git a/promgen/celery.py b/promgen/celery.py index e6e268f30..bda7fd434 100644 --- a/promgen/celery.py +++ b/promgen/celery.py @@ -1,7 +1,6 @@ # Copyright (c) 2017 LINE Corporation # These sources are released under the terms of the MIT license: see LICENSE -from __future__ import absolute_import, unicode_literals import logging import socket @@ -28,7 +27,7 @@ @app.task(bind=True) def debug_task(self): - print("Request: {0!r}".format(self.request)) + print(f"Request: {self.request!r}") @celeryd_after_setup.connect diff --git a/promgen/checks.py b/promgen/checks.py index 9e66ba7a8..c00a76125 100644 --- a/promgen/checks.py +++ b/promgen/checks.py @@ -14,7 +14,7 @@ def directories(**kwargs): path = pathlib.Path(util.setting(key)).parent except TypeError: yield checks.Warning( - "Missing setting for %s in %s " % (key, settings.PROMGEN_CONFIG_FILE), + f"Missing setting for {key} in {settings.PROMGEN_CONFIG_FILE} ", id="promgen.W001", ) else: @@ -29,7 +29,7 @@ def promtool(**kwargs): path = pathlib.Path(util.setting(key)) except TypeError: yield checks.Warning( - "Missing setting for %s in %s " % (key, settings.PROMGEN_CONFIG_FILE), + f"Missing setting for {key} in {settings.PROMGEN_CONFIG_FILE} ", id="promgen.W001", ) else: diff --git a/promgen/discovery/__init__.py b/promgen/discovery/__init__.py index 83d405e6a..707648096 100644 --- a/promgen/discovery/__init__.py +++ b/promgen/discovery/__init__.py @@ -5,7 +5,7 @@ FARM_DEFAULT = 'promgen' -class DiscoveryBase(object): +class DiscoveryBase: remote = True ''' diff --git a/promgen/forms.py b/promgen/forms.py index 2a8b899cd..ac149e83d 100644 --- a/promgen/forms.py +++ b/promgen/forms.py @@ -13,7 +13,7 @@ class ImportConfigForm(forms.Form): def _choices(): - return [('', '')] + sorted([(shard.name, 'Import into: ' + shard.name) for shard in models.Shard.objects.all()]) + return [('', '')] + sorted((shard.name, 'Import into: ' + shard.name) for shard in models.Shard.objects.all()) config = forms.CharField( widget=forms.Textarea(attrs={'rows': 5, 'class': 'form-control'}), @@ -177,7 +177,7 @@ def clean(self): # once we split on that, we want to make sure there are no invalid # hostnames hosts = set() - for hostname in re.split("[,\s]+", self.cleaned_data["hosts"]): + for hostname in re.split(r"[,\s]+", self.cleaned_data["hosts"]): if hostname == "": continue validators.hostname(hostname) diff --git a/promgen/management/commands/alerts-index.py b/promgen/management/commands/alerts-index.py index c8a78b481..27a0235f5 100644 --- a/promgen/management/commands/alerts-index.py +++ b/promgen/management/commands/alerts-index.py @@ -19,7 +19,7 @@ def handle(self, dryrun, **kargs): for alert in models.Alert.objects.filter(alertlabel__isnull=True): if dryrun: labels = alert.json.get("commonLabels") - self.stderr.write("alert_id: %s, labels: %s" % (alert.pk, labels)) + self.stderr.write(f"alert_id: {alert.pk}, labels: {labels}") continue tasks.index_alert.delay(alert.pk) diff --git a/promgen/management/commands/import-jobs.py b/promgen/management/commands/import-jobs.py index 7c4ac88bf..347860703 100644 --- a/promgen/management/commands/import-jobs.py +++ b/promgen/management/commands/import-jobs.py @@ -24,11 +24,11 @@ def handle(self, target_file, replace_shard, **kwargs): if imported: counters = {key: len(imported[key]) for key in imported} - self.stdout.write('Imported {}'.format(counters)) + self.stdout.write(f'Imported {counters}') if skipped: counters = {key: len(skipped[key]) for key in skipped} - self.stdout.write('Skipped {}'.format(counters)) + self.stdout.write(f'Skipped {counters}') trigger_write_config.send(self, force=True) trigger_write_rules.send(self, force=True) diff --git a/promgen/management/commands/register-exporter.py b/promgen/management/commands/register-exporter.py index 3343701b9..27cb4ef4e 100644 --- a/promgen/management/commands/register-exporter.py +++ b/promgen/management/commands/register-exporter.py @@ -23,7 +23,7 @@ def handle(self, job, port, path, **kargs): job=job, port=port, path=path ) if created: - self.stdout.write('Created {}'.format(exporter)) + self.stdout.write(f'Created {exporter}') else: - self.stdout.write('Already exists {}'.format(exporter)) + self.stdout.write(f'Already exists {exporter}') diff --git a/promgen/management/commands/register-server.py b/promgen/management/commands/register-server.py index 5bbc59def..551556121 100644 --- a/promgen/management/commands/register-server.py +++ b/promgen/management/commands/register-server.py @@ -23,11 +23,9 @@ def handle(self, shard, host, port, **kwargs): defaults={'shard': shard} ) if created: - self.stdout.write('Created {} on {}'.format(server, shard.name)) + self.stdout.write(f'Created {server} on {shard.name}') else: old_shard = server.shard server.shard = shard server.save() - self.stdout.write('Moved {} from {} to {}'.format( - server, old_shard.name, shard.name - )) + self.stdout.write(f'Moved {server} from {old_shard.name} to {shard.name}') diff --git a/promgen/middleware.py b/promgen/middleware.py index 78bac5380..3d10ff139 100644 --- a/promgen/middleware.py +++ b/promgen/middleware.py @@ -33,7 +33,7 @@ _user = local() -class PromgenMiddleware(object): +class PromgenMiddleware: def __init__(self, get_response): self.get_response = get_response diff --git a/promgen/migrations/0001_squashed_0044_common-rules.py b/promgen/migrations/0001_squashed_0044_common-rules.py index 86cabc93c..5f7d377c2 100644 --- a/promgen/migrations/0001_squashed_0044_common-rules.py +++ b/promgen/migrations/0001_squashed_0044_common-rules.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.10 on 2018-02-07 06:56 -from __future__ import unicode_literals from django.conf import settings import django.contrib.sites.models @@ -210,7 +208,7 @@ class Migration(migrations.Migration): ), migrations.AlterUniqueTogether( name='farm', - unique_together=set([('name', 'source')]), + unique_together={('name', 'source')}, ), migrations.AddField( model_name='exporter', @@ -219,14 +217,14 @@ class Migration(migrations.Migration): ), migrations.AlterUniqueTogether( name='prometheus', - unique_together=set([('host', 'port')]), + unique_together={('host', 'port')}, ), migrations.AlterUniqueTogether( name='host', - unique_together=set([('name', 'farm')]), + unique_together={('name', 'farm')}, ), migrations.AlterUniqueTogether( name='exporter', - unique_together=set([('job', 'port', 'project')]), + unique_together={('job', 'port', 'project')}, ), ] diff --git a/promgen/migrations/0002_auto_20180316_0525.py b/promgen/migrations/0002_auto_20180316_0525.py index c37d6ca81..07678e3b5 100644 --- a/promgen/migrations/0002_auto_20180316_0525.py +++ b/promgen/migrations/0002_auto_20180316_0525.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.10 on 2018-03-16 05:25 -from __future__ import unicode_literals from django.db import migrations, models diff --git a/promgen/models.py b/promgen/models.py index efb841bf1..8169063a2 100644 --- a/promgen/models.py +++ b/promgen/models.py @@ -91,7 +91,7 @@ def show_value(self): show_value.short_description = 'Value' def __str__(self): - return '{}:{}'.format(self.sender, self.show_value()) + return f'{self.sender}:{self.show_value()}' @classmethod def driver_set(cls): @@ -254,7 +254,7 @@ def get_absolute_url(self): return reverse('project-detail', kwargs={'pk': self.pk}) def __str__(self): - return '{} » {}'.format(self.service, self.name) + return f'{self.service} » {self.name}' class Farm(models.Model): @@ -270,7 +270,7 @@ def get_absolute_url(self): def refresh(self): target = set() - current = set(host.name for host in self.host_set.all()) + current = {host.name for host in self.host_set.all()} for entry in plugins.discovery(): if self.source == entry.name: target.update(entry.load()().fetch(self.name)) @@ -279,13 +279,13 @@ def refresh(self): add = target - current if add: - Audit.log('Adding {} to {}'.format(add, self), self) + Audit.log(f'Adding {add} to {self}', self) Host.objects.bulk_create([ Host(name=name, farm_id=self.id) for name in add ]) if remove: - Audit.log('Removing {} from {}'.format(add, self), self) + Audit.log(f'Removing {add} from {self}', self) Host.objects.filter(farm=self, name__in=remove).delete() return add, remove @@ -294,8 +294,7 @@ def refresh(self): def fetch(cls, source): for entry in plugins.discovery(): if entry.name == source: - for farm in entry.load()().farms(): - yield farm + yield from entry.load()().farms() @cached_property def driver(self): @@ -315,7 +314,7 @@ def driver_set(cls): yield entry.name, entry.load()() def __str__(self): - return '{} ({})'.format(self.name, self.source) + return f'{self.name} ({self.source})' class Host(models.Model): @@ -330,7 +329,7 @@ def get_absolute_url(self): return reverse('host-detail', kwargs={'slug': self.name}) def __str__(self): - return '{} [{}]'.format(self.name, self.farm.name) + return f'{self.name} [{self.farm.name}]' class BaseExporter(models.Model): @@ -375,7 +374,7 @@ class Probe(models.Model): description = models.TextField(blank=True) def __str__(self): - return "{} » {}".format(self.module, self.description) + return f"{self.module} » {self.description}" class URL(models.Model): @@ -387,7 +386,7 @@ class Meta: ordering = ["project__service", "project", "url"] def __str__(self): - return "{} [{}]".format(self.project, self.url) + return f"{self.project} [{self.url}]" class Rule(models.Model): @@ -438,7 +437,7 @@ def annotations(self): return _annotations def __str__(self): - return '{} [{}]'.format(self.name, self.content_object.name) + return f'{self.name} [{self.content_object.name}]' def get_absolute_url(self): return reverse('rule-detail', kwargs={'pk': self.pk}) @@ -470,15 +469,16 @@ def copy_to(self, content_type, object_id): orig_pk = self.pk self.pk = None self.parent_id = orig_pk - self.name = '{}_{}'.format(self.name, slugify(content_object.name)).replace('-', '_') + self.name = f'{self.name}_{slugify(content_object.name)}'.replace('-', '_') self.content_type = content_type self.object_id = object_id # Enable the copy by default since it's more likely the user prefers # to have their own copy enabled rather than the original one. self.enabled = True - self.clause = self.clause.replace(macro.EXCLUSION_MACRO, '{}="{}",{}'.format( - content_type.model, content_object.name, macro.EXCLUSION_MACRO - )) + self.clause = self.clause.replace( + macro.EXCLUSION_MACRO, + f'{content_type.model}="{content_object.name}",{macro.EXCLUSION_MACRO}', + ) self.save() # Add a label to our new rule by default, to help ensure notifications @@ -617,7 +617,7 @@ class Prometheus(models.Model): port = models.IntegerField() def __str__(self): - return '{}:{}'.format(self.host, self.port) + return f'{self.host}:{self.port}' class Meta: ordering = ['shard', 'host'] diff --git a/promgen/notification/__init__.py b/promgen/notification/__init__.py index aed59fbee..903c66881 100644 --- a/promgen/notification/__init__.py +++ b/promgen/notification/__init__.py @@ -24,7 +24,7 @@ class FormSenderBase(forms.Form): alias = forms.CharField(required=False) -class NotificationBase(object): +class NotificationBase: """ Base Notification class """ diff --git a/promgen/notification/user.py b/promgen/notification/user.py index a8dc6532f..468e1a2d8 100644 --- a/promgen/notification/user.py +++ b/promgen/notification/user.py @@ -12,13 +12,13 @@ def _choices(): - for user in User.objects.filter(is_active=True).order_by('username'): - if user.first_name: - yield (user.username, '{user.username} ({user.first_name} {user.last_name})'.format(user=user)) - elif user.email: - yield (user.username, '{user.username} ({user.email})'.format(user=user)) + for u in User.objects.filter(is_active=True).order_by("username"): + if u.first_name: + yield (u.username, f"{u.username} ({u.first_name} {u.last_name})") + elif u.email: + yield (u.username, f"{u.username} ({u.email})") else: - yield (user.username, user.username) + yield (u.username, u.username) class FormUser(forms.Form): @@ -42,8 +42,7 @@ def splay(self, address): except User.DoesNotExist: logger.error("Missing user %s", address) else: - for sender in models.Sender.objects.filter(obj=user): - yield sender + yield from models.Sender.objects.filter(obj=user) def _send(self, address, data): user = User.objects.get(username=address) diff --git a/promgen/prometheus.py b/promgen/prometheus.py index 4ad6981ca..f12f8c015 100644 --- a/promgen/prometheus.py +++ b/promgen/prometheus.py @@ -134,7 +134,7 @@ def render_config(service=None, project=None): hosts = [] for host in exporter.project.farm.host_set.all(): - hosts.append("{}:{}".format(host.name, exporter.port)) + hosts.append(f"{host.name}:{exporter.port}") data.append({"labels": labels, "targets": hosts}) return json.dumps(data, indent=2, sort_keys=True) diff --git a/promgen/proxy.py b/promgen/proxy.py index b9f228e51..770c3807e 100644 --- a/promgen/proxy.py +++ b/promgen/proxy.py @@ -62,15 +62,14 @@ def proxy(self, request): headers=self.headers, ) ) - for future in concurrent.futures.as_completed(futures): - yield future + yield from concurrent.futures.as_completed(futures) class ProxyGraph(TemplateView): template_name = "promgen/graph.html" def get_context_data(self, **kwargs): - context = super(ProxyGraph, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) context["shard_list"] = models.Shard.objects.filter(proxy=True) for k, v in self.request.GET.items(): _, k = k.split(".") diff --git a/promgen/signals.py b/promgen/signals.py index 4086e9199..140b45a58 100644 --- a/promgen/signals.py +++ b/promgen/signals.py @@ -42,7 +42,7 @@ def run_once(signal): def _decorator(func): @wraps(func) def _wrapper(*args, **kwargs): - key = '{}.{}'.format(func.__module__, func.__name__) + key = f'{func.__module__}.{func.__name__}' if 'force' in kwargs: logger.debug('Checking %s for %s', key, kwargs['sender']) kwargs.pop('force') @@ -83,7 +83,7 @@ def _trigger_write_config(signal, **kwargs): logger.info('Queueing write_config on %s', target) tasks.write_config.apply_async(queue=target) if 'request' in kwargs: - messages.info(kwargs['request'], 'Updating config on {}'.format(targets)) + messages.info(kwargs['request'], f'Updating config on {targets}') return True @@ -94,7 +94,7 @@ def _trigger_write_rules(signal, **kwargs): logger.info('Queueing write_rules on %s', target) tasks.write_rules.apply_async(queue=target) if 'request' in kwargs: - messages.info(kwargs['request'], 'Updating rules on {}'.format(targets)) + messages.info(kwargs['request'], f'Updating rules on {targets}') return True @@ -105,7 +105,7 @@ def _trigger_write_urls(signal, **kwargs): logger.info('Queueing write_urls on %s', target) tasks.write_urls.apply_async(queue=target) if 'request' in kwargs: - messages.info(kwargs['request'], 'Updating urls on {}'.format(targets)) + messages.info(kwargs['request'], f'Updating urls on {targets}') return True @@ -117,7 +117,7 @@ def update_log(sender, instance, **kwargs): # changes if instance.pk: old = sender.objects.get(pk=instance.pk) - models.Audit.log('Updated %s %s' % (sender.__name__, instance), instance, old) + models.Audit.log(f'Updated {sender.__name__} {instance}', instance, old) pre_save.connect(update_log, sender=models.Exporter) pre_save.connect(update_log, sender=models.Farm) pre_save.connect(update_log, sender=models.Host) @@ -133,7 +133,7 @@ def create_log(sender, instance, created, **kwargs): # primary key set so that we can link back to it using the ContentType # system. if created: - models.Audit.log('Created %s %s' % (sender.__name__, instance), instance) + models.Audit.log(f'Created {sender.__name__} {instance}', instance) post_save.connect(create_log, sender=models.Exporter) post_save.connect(create_log, sender=models.Farm) post_save.connect(create_log, sender=models.Host) @@ -144,7 +144,7 @@ def create_log(sender, instance, created, **kwargs): def delete_log(sender, instance, **kwargs): - models.Audit.log('Deleted %s %s' % (sender.__name__, instance), instance) + models.Audit.log(f'Deleted {sender.__name__} {instance}', instance) post_delete.connect(delete_log, sender=models.Exporter) post_delete.connect(delete_log, sender=models.Farm) post_delete.connect(delete_log, sender=models.Host) diff --git a/promgen/templatetags/promgen.py b/promgen/templatetags/promgen.py index f88373eb1..be54be647 100644 --- a/promgen/templatetags/promgen.py +++ b/promgen/templatetags/promgen.py @@ -70,7 +70,7 @@ def rulemacro(rule, clause=None): k: '|'.join(labels[k]) for k in sorted(labels) } macro = ','.join( - sorted('{}!~"{}"'.format(k, v) for k, v in filters.items()) + sorted(f'{k}!~"{v}"' for k, v in filters.items()) ) return clause.replace(EXCLUSION_MACRO, macro) diff --git a/promgen/tests/test_alert_rules.py b/promgen/tests/test_alert_rules.py index 138082a1b..ff6150397 100644 --- a/promgen/tests/test_alert_rules.py +++ b/promgen/tests/test_alert_rules.py @@ -140,7 +140,7 @@ def test_macro(self, mock_post): rules['project']['model'] = models.Rule.objects.get(pk=project_rule.pk) for k, r in rules.items(): - self.assertEquals(macro.rulemacro(r['model']), r['assert'], 'Expansion wrong for %s' % k) + self.assertEqual(macro.rulemacro(r['model']), r['assert'], 'Expansion wrong for %s' % k) @override_settings(PROMGEN=TEST_SETTINGS) @mock.patch('django.dispatch.dispatcher.Signal.send') diff --git a/promgen/tests/test_signals.py b/promgen/tests/test_signals.py index ea37bfeb7..5db1c3feb 100644 --- a/promgen/tests/test_signals.py +++ b/promgen/tests/test_signals.py @@ -26,7 +26,7 @@ def test_write_signal(self, write_mock, log_mock): ) # Should be called once for each created exporter - self.assertEquals(write_mock.call_count, 2, "Two write calls") + self.assertEqual(write_mock.call_count, 2, "Two write calls") write_mock.assert_has_calls([mock.call(e1), mock.call(e2)]) @mock.patch('promgen.models.Audit.log') diff --git a/promgen/util.py b/promgen/util.py index ff2d3d030..6b1057f53 100644 --- a/promgen/util.py +++ b/promgen/util.py @@ -15,7 +15,7 @@ # https://github.com/requests/requests/blob/master/requests/api.py -USER_AGENT = "promgen/{}".format(__version__) +USER_AGENT = f"promgen/{__version__}" ACCEPT_HEADER = "application/openmetrics-text; version=0.0.1,text/plain;version=0.0.4;q=0.5,*/*;q=0.1" diff --git a/promgen/views.py b/promgen/views.py index 2c16a24d0..240420506 100644 --- a/promgen/views.py +++ b/promgen/views.py @@ -141,7 +141,7 @@ class HostList(LoginRequiredMixin, ListView): ) def get_context_data(self, **kwargs): - context = super(HostList, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) context['host_groups'] = collections.defaultdict(list) for host in context['object_list']: context['host_groups'][host.name].append(host) @@ -293,14 +293,14 @@ def post(self, request, pk): if 'filter.pk' in request.POST: f = models.Filter.objects.get(pk=request.POST['filter.pk']) f.delete() - messages.success(request, 'Removed filter {f.name} {f.value}'.format(f=f)) + messages.success(request, f'Removed filter {f.name} {f.value}') if 'filter.name' in request.POST: obj = self.get_object() f, created = obj.filter_set.get_or_create(name=request.POST['filter.name'], value=request.POST['filter.value']) if created: - messages.success(request, 'Created filter {f.name} {f.value}'.format(f=f)) + messages.success(request, f'Created filter {f.name} {f.value}') else: - messages.warning(request, 'Updated filter {f.name} {f.value}'.format(f=f)) + messages.warning(request, f'Updated filter {f.name} {f.value}') if 'next' in request.POST: return redirect(request.POST['next']) return self.get(self, request, pk) @@ -372,8 +372,8 @@ def get_permission_required(self): obj = self.object._meta tgt = self.object.content_object._meta - yield '{}.delete_{}'.format(obj.app_label, obj.model_name) - yield '{}.change_{}'.format(tgt.app_label, tgt.model_name) + yield f'{obj.app_label}.delete_{obj.model_name}' + yield f'{tgt.app_label}.change_{tgt.model_name}' def get_success_url(self): return self.object.content_object.get_absolute_url() @@ -392,8 +392,8 @@ def get_permission_required(self): obj = self.object._meta tgt = self.object.content_object._meta - yield '{}.change_{}'.format(obj.app_label, obj.model_name) - yield '{}.change_{}'.format(tgt.app_label, tgt.model_name) + yield f'{obj.app_label}.change_{obj.model_name}' + yield f'{tgt.app_label}.change_{tgt.model_name}' def post(self, request, pk): self.object.enabled = not self.object.enabled @@ -425,7 +425,7 @@ class ProjectDetail(LoginRequiredMixin, DetailView): ) def get_context_data(self, **kwargs): - context = super(ProjectDetail, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) context['sources'] = models.Farm.driver_set() context['url_form'] = forms.URLForm() return context @@ -451,7 +451,7 @@ class FarmUpdate(LoginRequiredMixin, UpdateView): form_class = forms.FarmForm def get_context_data(self, **kwargs): - context = super(FarmUpdate, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) context['project'] = self.object.project_set.first() context['service'] = context['project'].service return context @@ -495,7 +495,7 @@ class RulesList(LoginRequiredMixin, ListView, mixins.ServiceMixin): queryset = models.Rule.objects.prefetch_related("content_type", "content_object") def get_context_data(self, **kwargs): - context = super(RulesList, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) site_rules = models.Rule.objects.filter( content_type__model="site", content_type__app_label="promgen" @@ -722,7 +722,7 @@ class ProjectUpdate(LoginRequiredMixin, UpdateView): fields = ["name", "description", "owner", "service", "shard"] def get_context_data(self, **kwargs): - context = super(ProjectUpdate, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) context["service"] = self.object.service context["shard_list"] = models.Shard.objects.all() return context @@ -759,8 +759,8 @@ def get_permission_required(self): obj = self.object._meta tgt = self.object.content_object._meta - yield "{}.change_{}".format(obj.app_label, obj.model_name) - yield "{}.change_{}".format(tgt.app_label, tgt.model_name) + yield f"{obj.app_label}.change_{obj.model_name}" + yield f"{tgt.app_label}.change_{tgt.model_name}" queryset = models.Rule.objects.prefetch_related( "content_object", "overrides", "overrides__content_object" @@ -769,7 +769,7 @@ def get_permission_required(self): form_class = forms.AlertRuleForm def get_context_data(self, **kwargs): - context = super(RuleUpdate, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) context.setdefault("formset_labels", forms.LabelFormset(instance=self.object)) context.setdefault("formset_annotations", forms.AnnotationFormset(instance=self.object)) context["macro"] = macro.EXCLUSION_MACRO @@ -814,11 +814,11 @@ def post(self, request, *args, **kwargs): # Save our labels for instance in form_labels.save(): - messages.info(request, "Added {} to {}".format(instance.name, self.object)) + messages.info(request, f"Added {instance.name} to {self.object}") # Save our annotations for instance in form_annotations.save(): - messages.info(request, "Added {} to {}".format(instance.name, self.object)) + messages.info(request, f"Added {instance.name} to {self.object}") return self.form_valid(form) @@ -932,7 +932,7 @@ class Profile(LoginRequiredMixin, FormView): template_name = "promgen/profile.html" def get_context_data(self, **kwargs): - context = super(Profile, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) context['discovery_plugins'] = [entry for entry in plugins.discovery()] context['notifier_plugins'] = [entry for entry in plugins.notifications()] context['notifiers'] = {'notifiers': models.Sender.objects.filter(obj=self.request.user)} @@ -951,7 +951,7 @@ class HostRegister(LoginRequiredMixin, FormView): form_class = forms.HostForm def get_context_data(self, **kwargs): - context = super(HostRegister, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) context["farm"] = get_object_or_404(models.Farm, pk=self.kwargs["pk"]) context["project"] = context["farm"].project_set.first() return context From 245ec2cf202c02038ce0ce062440502cc5669301 Mon Sep 17 00:00:00 2001 From: Paul Traylor Date: Mon, 13 Jun 2022 14:30:18 +0900 Subject: [PATCH 2/2] Add .git-blame-ignore-revs --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000..7b039315d --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# pyupgrade --py36-plus promgen/**/*.py +4d53038426aedf2abf337a2876d0d6ceccefc09b