Skip to content

Commit

Permalink
python: Modernize legacy Python 2 syntax with pyupgrade.
Browse files Browse the repository at this point in the history
Generated by `pyupgrade --py3-plus --keep-percent-format` on all our
Python code except `zthumbor` and `zulip-ec2-configure-interfaces`,
followed by manual indentation fixes.

Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk authored and timabbott committed Apr 9, 2020
1 parent fff2d39 commit c734bbd
Show file tree
Hide file tree
Showing 567 changed files with 1,878 additions and 2,565 deletions.
11 changes: 5 additions & 6 deletions analytics/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
Expand Down Expand Up @@ -90,22 +89,22 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='usercount',
unique_together=set([('user', 'property', 'end_time', 'interval')]),
unique_together={('user', 'property', 'end_time', 'interval')},
),
migrations.AlterUniqueTogether(
name='streamcount',
unique_together=set([('stream', 'property', 'end_time', 'interval')]),
unique_together={('stream', 'property', 'end_time', 'interval')},
),
migrations.AlterUniqueTogether(
name='realmcount',
unique_together=set([('realm', 'property', 'end_time', 'interval')]),
unique_together={('realm', 'property', 'end_time', 'interval')},
),
migrations.AlterUniqueTogether(
name='installationcount',
unique_together=set([('property', 'end_time', 'interval')]),
unique_together={('property', 'end_time', 'interval')},
),
migrations.AlterUniqueTogether(
name='huddlecount',
unique_together=set([('huddle', 'property', 'end_time', 'interval')]),
unique_together={('huddle', 'property', 'end_time', 'interval')},
),
]
3 changes: 1 addition & 2 deletions analytics/migrations/0002_remove_huddlecount.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations


Expand All @@ -11,7 +10,7 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterUniqueTogether(
name='huddlecount',
unique_together=set([]),
unique_together=set(),
),
migrations.RemoveField(
model_name='huddlecount',
Expand Down
1 change: 0 additions & 1 deletion analytics/migrations/0003_fillstate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations, models


Expand Down
1 change: 0 additions & 1 deletion analytics/migrations/0004_add_subgroup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations, models


Expand Down
1 change: 0 additions & 1 deletion analytics/migrations/0005_alter_field_size.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations, models


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations


Expand All @@ -11,18 +10,18 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterUniqueTogether(
name='installationcount',
unique_together=set([('property', 'subgroup', 'end_time', 'interval')]),
unique_together={('property', 'subgroup', 'end_time', 'interval')},
),
migrations.AlterUniqueTogether(
name='realmcount',
unique_together=set([('realm', 'property', 'subgroup', 'end_time', 'interval')]),
unique_together={('realm', 'property', 'subgroup', 'end_time', 'interval')},
),
migrations.AlterUniqueTogether(
name='streamcount',
unique_together=set([('stream', 'property', 'subgroup', 'end_time', 'interval')]),
unique_together={('stream', 'property', 'subgroup', 'end_time', 'interval')},
),
migrations.AlterUniqueTogether(
name='usercount',
unique_together=set([('user', 'property', 'subgroup', 'end_time', 'interval')]),
unique_together={('user', 'property', 'subgroup', 'end_time', 'interval')},
),
]
9 changes: 4 additions & 5 deletions analytics/migrations/0007_remove_interval.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-01-16 20:50
from django.db import migrations

Expand All @@ -12,31 +11,31 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterUniqueTogether(
name='installationcount',
unique_together=set([('property', 'subgroup', 'end_time')]),
unique_together={('property', 'subgroup', 'end_time')},
),
migrations.RemoveField(
model_name='installationcount',
name='interval',
),
migrations.AlterUniqueTogether(
name='realmcount',
unique_together=set([('realm', 'property', 'subgroup', 'end_time')]),
unique_together={('realm', 'property', 'subgroup', 'end_time')},
),
migrations.RemoveField(
model_name='realmcount',
name='interval',
),
migrations.AlterUniqueTogether(
name='streamcount',
unique_together=set([('stream', 'property', 'subgroup', 'end_time')]),
unique_together={('stream', 'property', 'subgroup', 'end_time')},
),
migrations.RemoveField(
model_name='streamcount',
name='interval',
),
migrations.AlterUniqueTogether(
name='usercount',
unique_together=set([('user', 'property', 'subgroup', 'end_time')]),
unique_together={('user', 'property', 'subgroup', 'end_time')},
),
migrations.RemoveField(
model_name='usercount',
Expand Down
7 changes: 3 additions & 4 deletions analytics/migrations/0008_add_count_indexes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-01 22:28
from django.db import migrations

Expand All @@ -13,14 +12,14 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterIndexTogether(
name='realmcount',
index_together=set([('property', 'end_time')]),
index_together={('property', 'end_time')},
),
migrations.AlterIndexTogether(
name='streamcount',
index_together=set([('property', 'realm', 'end_time')]),
index_together={('property', 'realm', 'end_time')},
),
migrations.AlterIndexTogether(
name='usercount',
index_together=set([('property', 'realm', 'end_time')]),
index_together={('property', 'realm', 'end_time')},
),
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
Expand Down
1 change: 0 additions & 1 deletion analytics/migrations/0010_clear_messages_sent_values.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
Expand Down
1 change: 0 additions & 1 deletion analytics/migrations/0011_clear_analytics_tables.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
Expand Down
2 changes: 0 additions & 2 deletions analytics/migrations/0012_add_on_delete.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-01-29 08:14
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models
Expand Down
2 changes: 0 additions & 2 deletions analytics/migrations/0013_remove_anomaly.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-02-02 02:47
from __future__ import unicode_literals

from django.db import migrations

Expand Down
2 changes: 0 additions & 2 deletions analytics/migrations/0014_remove_fillstate_last_modified.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.26 on 2020-01-27 04:32
from __future__ import unicode_literals

from django.db import migrations

Expand Down
1 change: 0 additions & 1 deletion analytics/migrations/0015_clear_duplicate_counts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
Expand Down
2 changes: 1 addition & 1 deletion analytics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def get_chart_data(request: HttpRequest, user_profile: UserProfile, chart_name:
"analytics cron job running?" % (realm.string_id, start, end))
raise JsonableError(_("No analytics data available. Please contact your server administrator."))

assert len(set([stat.frequency for stat in stats])) == 1
assert len({stat.frequency for stat in stats}) == 1
end_times = time_range(start, end, stats[0].frequency, min_length)
data = {'end_times': end_times, 'frequency': stats[0].frequency} # type: Dict[str, Any]

Expand Down
2 changes: 0 additions & 2 deletions confirmation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Copyright: (c) 2008, Jarek Zgoda <[email protected]>

# Permission is hereby granted, free of charge, to any person obtaining a
Expand Down
1 change: 0 additions & 1 deletion confirmation/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import models, migrations
import django.db.models.deletion

Expand Down
1 change: 0 additions & 1 deletion confirmation/migrations/0002_realmcreationkey.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import models, migrations
import django.utils.timezone

Expand Down
1 change: 0 additions & 1 deletion confirmation/migrations/0003_emailchangeconfirmation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-01-17 09:16
from django.db import migrations

Expand Down
1 change: 0 additions & 1 deletion confirmation/migrations/0004_remove_confirmationmanager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-07-08 04:23
from django.db import migrations, models

Expand Down
2 changes: 0 additions & 2 deletions confirmation/migrations/0005_confirmation_realm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-11-30 00:13
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-01-29 18:39
from __future__ import unicode_literals

from django.db import migrations, models

Expand Down
2 changes: 0 additions & 2 deletions confirmation/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Copyright: (c) 2008, Jarek Zgoda <[email protected]>

__revision__ = '$Id: models.py 28 2009-10-22 15:03:02Z jarek.zgoda $'
Expand Down
2 changes: 0 additions & 2 deletions confirmation/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Copyright: (c) 2008, Jarek Zgoda <[email protected]>

__revision__ = '$Id: settings.py 12 2008-11-23 19:38:52Z jarek.zgoda $'
Expand Down
2 changes: 0 additions & 2 deletions corporate/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.14 on 2018-09-25 12:02
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models
Expand Down
2 changes: 0 additions & 2 deletions corporate/migrations/0002_customer_default_discount.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-12-12 20:19
from __future__ import unicode_literals

from django.db import migrations, models

Expand Down
2 changes: 0 additions & 2 deletions corporate/migrations/0003_customerplan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-12-22 21:05
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models
Expand Down
2 changes: 0 additions & 2 deletions corporate/migrations/0004_licenseledger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-01-19 05:01
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models
Expand Down
2 changes: 0 additions & 2 deletions corporate/migrations/0005_customerplan_invoicing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-01-28 13:04
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models
Expand Down
2 changes: 0 additions & 2 deletions corporate/migrations/0006_nullable_stripe_customer_id.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-01-29 01:46
from __future__ import unicode_literals

from django.db import migrations, models

Expand Down
2 changes: 0 additions & 2 deletions corporate/migrations/0007_remove_deprecated_fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-01-31 22:16
from __future__ import unicode_literals

from django.db import migrations

Expand Down
2 changes: 0 additions & 2 deletions corporate/migrations/0008_nullable_next_invoice_date.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-04-11 00:45
from __future__ import unicode_literals

from django.db import migrations, models

Expand Down
12 changes: 6 additions & 6 deletions corporate/tests/test_stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def read_stripe_fixture(decorated_function_name: str,
def _read_stripe_fixture(*args: Any, **kwargs: Any) -> Any:
mock = operator.attrgetter(mocked_function_name)(sys.modules[__name__])
fixture_path = stripe_fixture_path(decorated_function_name, mocked_function_name, mock.call_count)
fixture = ujson.load(open(fixture_path, 'r'))
fixture = ujson.load(open(fixture_path))
# Check for StripeError fixtures
if "json_body" in fixture:
requestor = stripe.api_requestor.APIRequestor()
Expand Down Expand Up @@ -151,7 +151,7 @@ def normalize_fixture_data(decorated_function: CallableT,
normalized_values = {pattern: {}
for pattern in pattern_translations.keys()} # type: Dict[str, Dict[str, str]]
for fixture_file in fixture_files_for_function(decorated_function):
with open(fixture_file, "r") as f:
with open(fixture_file) as f:
file_content = f.read()
for pattern, translation in pattern_translations.items():
for match in re.findall(pattern, file_content):
Expand Down Expand Up @@ -214,7 +214,7 @@ def wrapped(*args: Any, **kwargs: Any) -> Any:

# A Kandra is a fictional character that can become anything. Used as a
# wildcard when testing for equality.
class Kandra(object): # nocoverage: TODO
class Kandra: # nocoverage: TODO
def __eq__(self, other: Any) -> bool:
return True

Expand Down Expand Up @@ -288,7 +288,7 @@ def upgrade(self, invoice: bool=False, talk_to_stripe: bool=True,

# Upgrade without talking to Stripe
def local_upgrade(self, *args: Any) -> None:
class StripeMock(object):
class StripeMock:
def __init__(self, depth: int=1):
self.id = 'id'
self.created = '1000'
Expand Down Expand Up @@ -1045,8 +1045,8 @@ def test_non_admins_blocked_from_json_endpoints(self) -> None:
# Make sure that we are testing all the JSON endpoints
# Quite a hack, but probably fine for now
string_with_all_endpoints = str(get_resolver('corporate.urls').reverse_dict)
json_endpoints = set([word.strip("\"'()[],$") for word in string_with_all_endpoints.split()
if 'json' in word])
json_endpoints = {word.strip("\"'()[],$") for word in string_with_all_endpoints.split()
if 'json' in word}
# No need to test upgrade endpoint as it only requires user to be logged in.
json_endpoints.remove("json/billing/upgrade")

Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# zulip-contributor-docs documentation build configuration file, created by
# sphinx-quickstart on Mon Aug 17 16:24:04 2015.
Expand Down
1 change: 0 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
from __future__ import (print_function)
import os
import sys
import configparser
Expand Down
1 change: 0 additions & 1 deletion pgroonga/migrations/0001_enable.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.conf import settings
from django.db import migrations

Expand Down
1 change: 0 additions & 1 deletion pgroonga/migrations/0002_html_escape_subject.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.db import connection, migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
Expand Down
1 change: 0 additions & 1 deletion pgroonga/migrations/0003_v2_api_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.conf import settings
from django.db import migrations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def nagios_from_file(results_file: str, max_time_diff: int=60 * 2) -> 'Tuple[int
This file is created by various nagios checking cron jobs such as
check-rabbitmq-queues and check-rabbitmq-consumers"""

with open(results_file, 'r') as f:
with open(results_file) as f:
data = f.read().strip()
pieces = data.split('|')

Expand Down
Loading

0 comments on commit c734bbd

Please sign in to comment.