Skip to content

Commit 27f5a0e

Browse files
Riolkuquantum5
authored andcommitted
Add flake8-quotes to the linter
Also fix all existing quoting issues
1 parent 56c111b commit 27f5a0e

31 files changed

+89
-87
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
with:
1111
python-version: 3.7
1212
- name: Install flake8
13-
run: pip install flake8 flake8-import-order flake8-future-import flake8-commas flake8-logging-format
13+
run: pip install flake8 flake8-import-order flake8-future-import flake8-commas flake8-logging-format flake8-quotes
1414
- name: Lint with flake8
1515
run: |
1616
flake8 --version

dmoj_install_pymysql.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import pymysql
22

33
pymysql.install_as_MySQLdb()
4-
pymysql.version_info = (1, 3, 13, "final", 0)
4+
pymysql.version_info = (1, 3, 13, 'final', 0)

judge/admin/runtime.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GenerateKeyTextInput(TextInput):
4949
def render(self, name, value, attrs=None, renderer=None):
5050
text = super(TextInput, self).render(name, value, attrs)
5151
return mark_safe(text + format_html(
52-
'''\
52+
"""\
5353
<a href="#" onclick="return false;" class="button" id="id_{0}_regen">Regenerate</a>
5454
<script type="text/javascript">
5555
django.jQuery(document).ready(function ($) {{
@@ -61,7 +61,7 @@ def render(self, name, value, attrs=None, renderer=None):
6161
}});
6262
}});
6363
</script>
64-
''', name))
64+
""", name))
6565

6666

6767
class JudgeAdminForm(ModelForm):

judge/contest_format/atcoder.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class AtCoderContestFormat(DefaultContestFormat):
1919
name = gettext_lazy('AtCoder')
2020
config_defaults = {'penalty': 5}
2121
config_validators = {'penalty': lambda x: x >= 0}
22-
'''
22+
"""
2323
penalty: Number of penalty minutes each incorrect submission adds. Defaults to 5.
24-
'''
24+
"""
2525

2626
@classmethod
2727
def validate(cls, config):
@@ -51,7 +51,7 @@ def update_participation(self, participation):
5151
format_data = {}
5252

5353
with connection.cursor() as cursor:
54-
cursor.execute('''
54+
cursor.execute("""
5555
SELECT MAX(cs.points) as `score`, (
5656
SELECT MIN(csub.date)
5757
FROM judge_contestsubmission ccs LEFT OUTER JOIN
@@ -62,7 +62,7 @@ def update_participation(self, participation):
6262
judge_contestsubmission cs ON (cs.problem_id = cp.id AND cs.participation_id = %s) LEFT OUTER JOIN
6363
judge_submission sub ON (sub.id = cs.submission_id)
6464
GROUP BY cp.id
65-
''', (participation.id, participation.id))
65+
""", (participation.id, participation.id))
6666

6767
for score, time, prob in cursor.fetchall():
6868
time = from_database_time(time)

judge/contest_format/ecoo.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ class ECOOContestFormat(DefaultContestFormat):
1818
name = gettext_lazy('ECOO')
1919
config_defaults = {'cumtime': False, 'first_ac_bonus': 10, 'time_bonus': 5}
2020
config_validators = {'cumtime': lambda x: True, 'first_ac_bonus': lambda x: x >= 0, 'time_bonus': lambda x: x >= 0}
21-
'''
21+
"""
2222
cumtime: Specify True if cumulative time is to be used in breaking ties. Defaults to False.
2323
first_ac_bonus: The number of points to award if a solution gets AC on its first non-IE/CE run. Defaults to 10.
2424
time_bonus: Number of minutes to award an extra point for submitting before the contest end.
2525
Specify 0 to disable. Defaults to 5.
26-
'''
26+
"""
2727

2828
@classmethod
2929
def validate(cls, config):

judge/contest_format/icpc.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class ICPCContestFormat(DefaultContestFormat):
1919
name = gettext_lazy('ICPC')
2020
config_defaults = {'penalty': 20}
2121
config_validators = {'penalty': lambda x: x >= 0}
22-
'''
22+
"""
2323
penalty: Number of penalty minutes each incorrect submission adds. Defaults to 20.
24-
'''
24+
"""
2525

2626
@classmethod
2727
def validate(cls, config):
@@ -52,7 +52,7 @@ def update_participation(self, participation):
5252
format_data = {}
5353

5454
with connection.cursor() as cursor:
55-
cursor.execute('''
55+
cursor.execute("""
5656
SELECT MAX(cs.points) as `points`, (
5757
SELECT MIN(csub.date)
5858
FROM judge_contestsubmission ccs LEFT OUTER JOIN
@@ -63,7 +63,7 @@ def update_participation(self, participation):
6363
judge_contestsubmission cs ON (cs.problem_id = cp.id AND cs.participation_id = %s) LEFT OUTER JOIN
6464
judge_submission sub ON (sub.id = cs.submission_id)
6565
GROUP BY cp.id
66-
''', (participation.id, participation.id))
66+
""", (participation.id, participation.id))
6767

6868
for points, time, prob in cursor.fetchall():
6969
time = from_database_time(time)

judge/contest_format/ioi.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
class IOIContestFormat(LegacyIOIContestFormat):
1111
name = gettext_lazy('IOI')
1212
config_defaults = {'cumtime': False}
13-
'''
13+
"""
1414
cumtime: Specify True if time penalties are to be computed. Defaults to False.
15-
'''
15+
"""
1616

1717
def update_participation(self, participation):
1818
cumtime = 0
1919
score = 0
2020
format_data = {}
2121

2222
with connection.cursor() as cursor:
23-
cursor.execute('''
23+
cursor.execute("""
2424
SELECT q.prob,
2525
MIN(q.date) as `date`,
2626
q.batch_points
@@ -64,7 +64,7 @@ def update_participation(self, participation):
6464
ON p.prob = q.prob AND (p.batch = q.batch OR p.batch is NULL AND q.batch is NULL)
6565
WHERE p.max_batch_points = q.batch_points
6666
GROUP BY q.prob, q.batch
67-
''', (participation.id, participation.id))
67+
""", (participation.id, participation.id))
6868

6969
for problem_id, time, subtask_points in cursor.fetchall():
7070
problem_id = str(problem_id)

judge/contest_format/legacy_ioi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
class LegacyIOIContestFormat(DefaultContestFormat):
1818
name = gettext_lazy('IOI (pre-2016)')
1919
config_defaults = {'cumtime': False}
20-
'''
20+
"""
2121
cumtime: Specify True if time penalties are to be computed. Defaults to False.
22-
'''
22+
"""
2323

2424
@classmethod
2525
def validate(cls, config):

judge/highlight_code.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ def _make_pre_code(code):
88

99

1010
def _wrap_code(inner):
11-
yield 0, "<code>"
11+
yield 0, '<code>'
1212
for tup in inner:
1313
yield tup
14-
yield 0, "</code>"
14+
yield 0, '</code>'
1515

1616

1717
try:

judge/jinja2/markdown/test_markdown.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
from . import fragment_tree_to_str, fragments_to_tree, get_cleaner, markdown
55

6-
MATHML_N = '''\
6+
MATHML_N = """\
77
<math xmlns="http://www.w3.org/1998/Math/MathML">
88
<semantics>
99
<mi>N</mi>
1010
<annotation encoding="application/x-tex">N</annotation>
1111
</semantics>
1212
</math>
13-
'''
13+
"""
1414

15-
MATHML_CHUDNOVSKY = r'''
15+
MATHML_CHUDNOVSKY = r"""
1616
<math xmlns="http://www.w3.org/1998/Math/MathML"
1717
alttext="{\displaystyle {\frac {1}{\pi }}=12\sum _{k=0}^{\infty }{\frac {(-1)^{k}(6k)!(545140134k+13591409)}{(3k)!(k!)^{3}\left(640320\right)^{3k+3/2}}}}">
1818
<semantics>
@@ -101,7 +101,7 @@
101101
<annotation encoding="application/x-tex">{\displaystyle {\frac {1}{\pi }}=12\sum _{k=0}^{\infty }{\frac {(-1)^{k}(6k)!(545140134k+13591409)}{(3k)!(k!)^{3}\left(640320\right)^{3k+3/2}}}}</annotation>
102102
</semantics>
103103
</math>
104-
''' # noqa: E501
104+
""" # noqa: E501
105105

106106

107107
class TestMarkdown(SimpleTestCase):

judge/management/commands/adduser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def add_arguments(self, parser):
1616
help='default language ID for user')
1717

1818
parser.add_argument('--superuser', action='store_true', default=False,
19-
help="if specified, creates user with superuser privileges")
19+
help='if specified, creates user with superuser privileges')
2020
parser.add_argument('--staff', action='store_true', default=False,
21-
help="if specified, creates user with staff privileges")
21+
help='if specified, creates user with staff privileges')
2222

2323
def handle(self, *args, **options):
2424
usr = User(username=options['name'], email=options['email'], is_active=True)

judge/management/commands/makedmojmessages.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def add_arguments(self, parser):
2222
parser.add_argument('--no-wrap', action='store_true', dest='no_wrap',
2323
default=False, help="Don't break long message lines into several lines.")
2424
parser.add_argument('--no-obsolete', action='store_true', dest='no_obsolete',
25-
default=False, help="Remove obsolete message strings.")
25+
default=False, help='Remove obsolete message strings.')
2626
parser.add_argument('--keep-pot', action='store_true', dest='keep_pot',
27-
default=False, help="Keep .pot file after making messages. Useful when debugging.")
27+
default=False, help='Keep .pot file after making messages. Useful when debugging.')
2828

2929
def handle(self, *args, **options):
3030
locale = options.get('locale')
@@ -97,7 +97,7 @@ def handle(self, *args, **options):
9797
# Build po files for each selected locale
9898
for locale in locales:
9999
if self.verbosity > 0:
100-
self.stdout.write("processing locale %s\n" % locale)
100+
self.stdout.write('processing locale %s\n' % locale)
101101
for potfile in potfiles:
102102
self.write_po_file(potfile, locale)
103103
finally:
@@ -108,10 +108,10 @@ def find_files(self, root):
108108
return []
109109

110110
def _emit_message(self, potfile, string):
111-
potfile.write('''
111+
potfile.write("""
112112
msgid "%s"
113113
msgstr ""
114-
''' % string.replace('\\', r'\\').replace('\t', '\\t').replace('\n', '\\n').replace('"', '\\"'))
114+
""" % string.replace('\\', r'\\').replace('\t', '\\t').replace('\n', '\\n').replace('"', '\\"'))
115115

116116
def process_files(self, file_list):
117117
with io.open(os.path.join(self.default_locale_path, 'dmoj-user.pot'), 'w', encoding='utf-8') as potfile:

judge/management/commands/runmoss.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def handle(self, *args, **options):
2828
for problem in Contest.objects.get(key=contest).problems.order_by('code'):
2929
print('========== %s / %s ==========' % (problem.code, problem.name))
3030
for dmoj_lang, moss_lang in self.LANG_MAPPING:
31-
print("%s: " % dmoj_lang, end=' ')
31+
print('%s: ' % dmoj_lang, end=' ')
3232
subs = Submission.objects.filter(
3333
contest__participation__virtual__in=(ContestParticipation.LIVE, ContestParticipation.SPECTATE),
3434
contest__participation__contest__key=contest,

judge/migrations/0085_submission_source.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class Migration(migrations.Migration):
2020
],
2121
),
2222
migrations.RunSQL(
23-
['''INSERT INTO judge_submissionsource (source, submission_id)
24-
SELECT source, id AS 'submission_id' FROM judge_submission;'''],
25-
['''UPDATE judge_submission sub
23+
["""INSERT INTO judge_submissionsource (source, submission_id)
24+
SELECT source, id AS 'submission_id' FROM judge_submission;"""],
25+
["""UPDATE judge_submission sub
2626
INNER JOIN judge_submissionsource src ON sub.id = src.submission_id
27-
SET sub.source = src.source;'''],
27+
SET sub.source = src.source;"""],
2828
elidable=True,
2929
),
3030
migrations.RemoveField(

judge/migrations/0089_submission_to_contest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ class Migration(migrations.Migration):
1616
name='contest_object',
1717
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='judge.Contest', verbose_name='contest'),
1818
),
19-
migrations.RunSQL('''
19+
migrations.RunSQL("""
2020
UPDATE `judge_submission`
2121
INNER JOIN `judge_contestsubmission`
2222
ON (`judge_submission`.`id` = `judge_contestsubmission`.`submission_id`)
2323
INNER JOIN `judge_contestparticipation`
2424
ON (`judge_contestsubmission`.`participation_id` = `judge_contestparticipation`.`id`)
2525
SET `judge_submission`.`contest_object_id` = `judge_contestparticipation`.`contest_id`
26-
''', migrations.RunSQL.noop),
26+
""", migrations.RunSQL.noop),
2727
]

judge/migrations/0090_fix_contest_visibility.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ class Migration(migrations.Migration):
88
]
99

1010
operations = [
11-
migrations.RunSQL('''
11+
migrations.RunSQL("""
1212
UPDATE `judge_contest`
1313
SET `judge_contest`.`is_private` = 0, `judge_contest`.`is_organization_private` = 1
1414
WHERE `judge_contest`.`is_private` = 1
15-
''', '''
15+
""", """
1616
UPDATE `judge_contest`
1717
SET `judge_contest`.`is_private` = `judge_contest`.`is_organization_private`
18-
'''),
18+
"""),
1919
]

judge/models/contest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Contest(models.Model):
9191
max_length=1, help_text=_('Scoreboard visibility through the duration '
9292
'of the contest'), choices=SCOREBOARD_VISIBILITY)
9393
use_clarifications = models.BooleanField(verbose_name=_('no comments'),
94-
help_text=_("Use clarification system instead of comments."),
94+
help_text=_('Use clarification system instead of comments.'),
9595
default=True)
9696
rating_floor = models.IntegerField(verbose_name=('rating floor'), help_text=_('Rating floor for contest'),
9797
null=True, blank=True)
@@ -522,7 +522,7 @@ class ContestProblem(models.Model):
522522
'or leave blank for no limit.'),
523523
default=None, null=True, blank=True,
524524
validators=[MinValueOrNoneValidator(1, _('Why include a problem you '
525-
'can\'t submit to?'))])
525+
"can't submit to?"))])
526526

527527
class Meta:
528528
unique_together = ('problem', 'contest')

judge/models/profile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def generate_api_token(self):
200200

201201
def generate_scratch_codes(self):
202202
def generate_scratch_code():
203-
return "".join(secrets.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567") for _ in range(16))
203+
return ''.join(secrets.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567') for _ in range(16))
204204
codes = [generate_scratch_code() for _ in range(settings.DMOJ_SCRATCH_CODES_COUNT)]
205205
self.scratch_codes = json.dumps(codes)
206206
self.save(update_fields=['scratch_codes'])

judge/models/runtime.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Language(models.Model):
3838
help_text=_('Code template to display in submission editor.'), blank=True)
3939
info = models.CharField(max_length=50, verbose_name=_('runtime info override'), blank=True,
4040
help_text=_("Do not set this unless you know what you're doing! It will override the "
41-
"usually more specific, judge-provided runtime info!"))
41+
'usually more specific, judge-provided runtime info!'))
4242
description = models.TextField(verbose_name=_('language description'),
4343
help_text=_('Use this field to inform users of quirks with your environment, '
4444
'additional restrictions, etc.'), blank=True)

judge/models/submission.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Submission(models.Model):
4747
USER_DISPLAY_CODES = {
4848
'AC': _('Accepted'),
4949
'WA': _('Wrong Answer'),
50-
'SC': "Short Circuited",
50+
'SC': 'Short Circuited',
5151
'TLE': _('Time Limit Exceeded'),
5252
'MLE': _('Memory Limit Exceeded'),
5353
'OLE': _('Output Limit Exceeded'),

judge/models/tests/test_contest.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def setUpTestData(self):
6161
end_time=_now + timezone.timedelta(days=100),
6262
is_visible=True,
6363
scoreboard_visibility=Contest.SCOREBOARD_AFTER_CONTEST,
64-
problem_label_script='''
64+
problem_label_script="""
6565
function(n)
6666
return tostring(math.floor(n))
6767
end
68-
''',
68+
""",
6969
)
7070

7171
self.hidden_scoreboard_non_staff_author = create_contest(
@@ -711,11 +711,11 @@ def test_contest_clean(self):
711711
contest.format_config = {}
712712
with self.assertRaisesRegex(ValidationError, 'Contest problem label script'):
713713
contest.full_clean()
714-
contest.problem_label_script = '''
714+
contest.problem_label_script = """
715715
function(n)
716716
return n
717717
end
718-
'''
718+
"""
719719
# Test for bad problem label script caching
720720
with self.assertRaisesRegex(ValidationError, 'Contest problem label script'):
721721
contest.full_clean()

0 commit comments

Comments
 (0)